elbow has asked for the wisdom of the Perl Monks concerning the following question:
Whenever I have had to access files from a directory before I've used the approach:-while ($file = <$dir\\*.txt>) { #do your stuff }
Benchmarking shows only a small difference in performance, with opendir the slightly better of the two.opendir ( DIR, $dir ) || die "Cannot open directory $dir: $!"; while ( defined( $file = readdir(DIR) ) ) { next if $file =~ /^\.\.?$/; if ( $file =~/txt$/ ) { #do your stuff } } closedir DIR;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: opendir or not?
by davido (Cardinal) on Feb 02, 2004 at 09:06 UTC | |
|
Re: opendir or not?
by Hena (Friar) on Feb 02, 2004 at 09:49 UTC | |
|
Re: opendir or not?
by halley (Prior) on Feb 02, 2004 at 15:21 UTC |