in reply to RE: RE: Re: Advanced Sorting
in thread Advanced Sorting

When I try to understand it, my brain hurts, because that'll be grossly inefficient (and perhaps even wrong if things change out from under you) for a dozen files or more. Consider the Schwartzian Transform instead.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: RE: RE: Re: Advanced Sorting
by little (Curate) on Oct 28, 2000 at 21:49 UTC
    #!/usr/local/bin/perl use strict; $|++; my $dir = "../../logs/"; my $output = "../stats/current.txt"; #read the dir and put all files to a list opendir DIR, $dir || die "blah!"; my @allfiles = readdir DIR; close DIR; # remove those files from list that don't seem to be logfiles my @logs = grep /^\d{6}.?\.log$/i, @allfiles; # sort in a way you like my @sorted = map{ $_->[0] } sort {$a->[1] cmp $b->[1]} map { [ substr($_,2,2).substr($_,0,2).substr($_,4)] } @logs; # start output open OUTPUT, ">$output" || die "blah!"; print OUTPUT join "\n", @logs; close OUTPUT; # end output