Ryan Frantz wrote:
> Perlers,
> 
> I'm working on a script that will generate a listing of files on a
> regular basis so that I can create hyperlinks to each respective file.
> As you see from the sorted output below, though it is in ASCIIbetical
> order, it is not in chronological order:
> 
> /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
> 
> Is there any decent documentation available that I could study so
> that I can sort this better?
> 
> I thought about grabbing the ctime of each file and sorting on that
> but I'm not sure if that would add unnecessary complexity to the
> script. 
> 
> Incidentally, these files are created by SARG (Squid log analyzer) and
> I've found nothing in the config that lets me customize the naming
> convention for the directories.
> 
> ry
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";
 }

__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

Wags ;)


*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to