Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, how can I print from this file,
Record 0: Coll 02/14/2003 Charles S. 2862.30 00000 ISSUE WWW Record 1: Coll 03/17/2003 Peter C. 392.50 00000 ISSUE WWW Record 2: Coll 07/25/2003 John K. 10.00 00000 ISSUE CCC

the most recent "date" line? I try sorting it but with no success.
I just want to print the line with the most recent date; based on the example file I would print
Record 2: Coll 07/25/2003 John K. 10.00 00000 ISSUE CCC

Any help!

Replies are listed 'Best First'.
Re: Recent Date Problem
by artist (Parson) on Apr 01, 2004 at 20:22 UTC
    use strict; use warnings; my @records = <DATA>; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_,datify((/Coll\s+(\S+)/)[0]) ] } @records; print pop @sorted; sub datify { return join "" => (split '/',shift)[2,0,1]; } __DATA__ Record 0: Coll 02/14/2003 Charles S. 2862.30 00000 ISSUE WWW Record 1: Coll 03/17/2003 Peter C. 392.50 00000 ISSUE WWW Record 2: Coll 07/25/2003 John K. 10.00 00000 ISSUE CCC
Re: Recent Date Problem
by matija (Priest) on Apr 01, 2004 at 19:24 UTC
    The problem with the dates as you have them is that they are not in a form readily sortable. You could split the date on the "/" and re-assemble it as a string of the form YYYYMMDD then use that as a key to sort dates. (Look for Schwartizan transform on this site).