in reply to Re^2: How to re-order badly formed dates within a delimited string?
in thread How to re-order badly formed dates within a delimited string?

OK, in that case you must re-sort the file with the list of dates.

As this involves parsing every record (a potentially "expensive" operation, to be repeated for every comparison in the sort) the "Schwartzian Transform" will come to your rescue:

use strict; use DateTime::Format::Strptime; my $dtf = new DateTime::Format::Strptime( pattern => '%a %d-%b-%y', lo +cale => 'en_US'); my @events = <DATA>; my @sorted_events = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, $dtf->parse_datetime( (split /\|/)[14])->ymd ] } @events; print @sorted_events; # now you save the array of sorted events and "feed" that to your scri +pt __DATA__ |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sat 09-DEC-06| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sat 09-JUN-07| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sat 10-FEB-07| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sat 14-APR-07| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sat 28-OCT-06| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sun 10-DEC-06| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sun 10-JUN-07| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sun 15-APR-07| |Puerto Rico||Santiago Apostol Catholic School|Las Croabas Road, Urb S +anta Isidra|Fajardo|PR||00738|Modesto|Garcia|Counselor|787/863-0524|7 +87/863-6655|Sun 29-OCT-06|

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

  • Comment on Re^3: How to re-order badly formed dates within a delimited string?
  • Download Code