Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is used to compare date read from a file stored in a array ?

Status
Not open for further replies.

Rajey

Programmer
Feb 2, 2005
11
US
I have a file which has date like 2/23/2006, this is stored in array then lets assume it is stored in array1[0]

i have another array2 that also has date from a file in the same format I need to compare array1[0] to array2[0] i am not sure if i can use == or eq

 
I am planning to just check using a if statement if the array1[0] is equal to array2[0] if they match i need to print that they match

but I am not sure what perl will interpret 2/23/2006 as i just need to compare if the value match not a time match

Thanks
 
I ended up with
Code:
sub sort_date
  {
  my ( $aday, $amonth, $ayear ) = split '/', $a;
  my ( $bday, $bmonth, $byear ) = split '/', $b;
  my $return = ( $ayear <=> $byear );
  ! $return and $return = ( $amonth <=> $bmonth );
  ! $return and $return = ( $aday <=> $bday );
  return $return;
  }
But I'm sure there are those who could provide better code.

Columb Healy
 
if you just want to see if the dates match you can use 'eq'.

Code:
foreach my $i (@array1) {
if ($array1[$i] eq $array2[$i]) {
   print "They are the same\n";
}

this assumes both arrays are the same size.
 
Put them in Hashs instead of arrays.
# Trys all the keys in the first hash and if they are in the second it prints them.

foreach (keys %hash1) {
if ($hash2{$_}){
print $_;
}
}
 
Thanks to all of you this has been helpful
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top