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
In reply to Re^2: how to do effective sort in perl
by Hue-Bond
in thread how to do effective sort in perl
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |