> Here is one way to approach:
> !perl
>
> use strict;
> use warnings;
>
> my %AlphaToNbr = qw(jan 1 feb 2 mar 3 apr 4 may 5 jun 6 jul 7 aug 8
sep 9
> oct 10 nov 11 dec 12);
> foreach my $MySortedFile (sort { $a->[1] <=> $b->[1]
> or
> $AlphaToNbr{lc($a->[2])} <=>
$AlphaToNbr{lc($b-
> >[2])} or
> $a->[3] <=> $b->[3]
> }
> map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}
> <DATA> ) {
> chomp($MySortedFile->[0]);
> print $MySortedFile->[0] . "\n";
> }
>
I have a rudimentary understanding of the above now (from reading Ch 15
of 'Learning Perl' and the perlreftut manpage). This is what I grok
(assuming a YYYYmmmDD format):
1. Create a hash with numeric equivalents for the months.
2. Perform a sort by first comparing numbers (I'm assuming the YYYY, but
I don't quite know how that reference works).
3. Then comparing mmm (having been converted to lower case, the value of
the respective AlphaToNbr key is compared).
4. Compare another pair of numbers (DD?)
After that I'm lost. I'm not familiar with the 'map' function or what
happens after that.
Also, you use an imaginary scalar that would contain the data. I have
the data in an array and tried to use your sortsub as follows (taking
some cues from the LP book); I think I'm off base...
----begin snip----
(omitted creation of array @user_links)
my %AlphaToNumber = (
jan => "1",
feb => "2",
mar => "3",
apr => "4",
may => "5",
jun => "6",
jul => "7",
aug => "8",
sep => "9",
"oct" => "10",
nov => "11",
dec => "12",
);
# sort chronologically using a code snippet from 'Wags'
@user_links = ( sort {
$a->[1] <=> $b->[1]
or
$AlphaToNumber{lc($a->[2])} <=> $AlphaToNumber{lc($b->[2])}
or
$a->[3] <=> $b->[3]
} @user_links;
map {[$_, /^.(\d{4})(\w{3})(\d{2})/]}
<DATA> );
----end snip----
> __DATA__
> /2005Jul01-2005Jul02/foo/bar.html
> /2005Jul05-2005Jul06/foo/bar.html
> /2005Jun09-2005Jun10/foo/bar.html
> /2005Jun10-2005Jun11/foo/bar.html
> /2005Jun13-2005Jun14/foo/bar.html
> /2005Jun14-2005Jun15/foo/bar.html
>
> Output:
> /2005Jun09-2005Jun10/foo/bar.html
> /2005Jun10-2005Jun11/foo/bar.html
> /2005Jun13-2005Jun14/foo/bar.html
> /2005Jun14-2005Jun15/foo/bar.html
> /2005Jul01-2005Jul02/foo/bar.html
> /2005Jul05-2005Jul06/foo/bar.html
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>