leocharre has asked for the wisdom of the Perl Monks concerning the following question:
I have a directory with 100,000 file entries. I want to pull out 5 filenames in no particular order. What's a quick way to do this?
One thing I can think of is using readdir in non list context. By comparison, reading a directory in list context can take a long time (a few seconds).
Maybe something like..
Maybe there's some other interesting way to do this?my $abs_d = './'; my @f; opendir(DIR,$abs_d) or die; for my $filename ( readdir(DIR) ){ next if $filename=~/^\.+$/; push @f, $filename; last if $#f == 4; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: quick way to read a few directory entries of many
by ikegami (Patriarch) on Jun 05, 2008 at 14:40 UTC | |
|
Re: quick way to read a few directory entries of many
by swampyankee (Parson) on Jun 05, 2008 at 17:16 UTC | |
by leocharre (Priest) on Jun 05, 2008 at 18:14 UTC | |
by almut (Canon) on Jun 05, 2008 at 18:58 UTC | |
by ikegami (Patriarch) on Jun 06, 2008 at 01:00 UTC | |
by chrism01 (Friar) on Jun 06, 2008 at 05:36 UTC | |
|
Re: quick way to read a few directory entries of many
by Fletch (Bishop) on Jun 05, 2008 at 14:54 UTC | |
|
Re: quick way to read a few directory entries of many
by kgraff (Monk) on Jun 05, 2008 at 16:55 UTC | |
by leocharre (Priest) on Jun 05, 2008 at 18:23 UTC |