On Thu, May 1, 2008 at 5:04 AM, Andy <[EMAIL PROTECTED]> wrote:
>
> Basically I need to be able to pull the latest data.
>
> for instance
>
> 155073040~06/04/1998
> 155073040~04/28/1998
> 155073040~04/29/1998
>
> Has 3 Id Numbers for the same data.
>
> If Id's are the same Pull Latest Data?
>
> so If I pulled this I would only get
>
> 155073040~06/04/1998
>
Try this:
use strict;
use Time::Local;
my %hash;
while(<DATA>) {
chomp;
my ($id,$date) = split/\~/;
if (exists $hash{$id} ){
my $time_old = gettime($hash{$id});
my $time_new = gettime($date);
$hash{$id} = $date if $time_new > $time_old;
} else {
$hash{$id} = $date;
}
}
for (keys %hash) {
print $_,"~",$hash{$_},"\n";
}
sub gettime{
my ($m,$d,$y) = split/\//,+shift;
return timelocal(0,0,0,$d,$m -1,$y);
}
__DATA__
155073040~06/04/1998
155073040~04/28/1998
155073040~04/29/1998
255256040~04/29/1998
255293040~05/27/1999
255322040~12/09/1999
55322040~12/08/1999
755379040~04/30/1998
755383040~04/30/1998
755412040~01/19/1999
755612040~04/19/2000
755633040~04/26/1999
755763040~06/04/1998
--
J. Peng - QQMail Operation Team
eMail: [EMAIL PROTECTED] AIM: JeffHua
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/