in reply to how to do effective sort in perl

On my OS I'd do

my @files = glob '*';

as glob always produces a sorted list on my system. I'm not sure if that is true on other systems?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: how to do effective sort in perl
by Hue-Bond (Priest) on May 03, 2006 at 15:06 UTC

    On some OSs that doesn't include hidden files:

    $ perl -le 'opendir my $fd, "."; my @files = readdir $fd; closedir $fd +; print scalar @files' 48 $ perl -le 'my @files = <*>; print scalar @files' 7 $ _

    But including them is not difficult:

    $ perl -le 'my @files = (<*>,<.*>); print scalar @files' 48 $ _

    It seems that readdir is faster, though:

    use Benchmark qw(:all) ; cmpthese(20000, { readdir => sub { opendir my $fd, "."; my @files = readdir $fd; close +dir $fd; }, glob => sub { my @files = (<*>,<.*>); } }); __END__ Rate glob readdir glob 3170/s -- -75% readdir 12739/s 302% --

    Update: Of course glob is slower, since in this computer it also sorts the result.

    --
    David Serrano