Dr.Ruud wrote:
> Mathew Snyder schreef:
>> Dr.Ruud:
>
>>> my @filenames = sort grep -f, readdir DH;
>> I tried this line using $dh. Nothing was getting placed in the array.
>> Would that be because everything in /usr/bin is an executable file?
>
> Aaargh no, I am making the same mistake as you did: not prepending the
> directory name.
> I overlooked that readdir() returns the filename, not a handle.
>
> my @filenames = grep -f "$dir/$_", sort readdir DH;
>
Interesting. The above line returns 1648 items while the following
@filenames = sort grep { !/^\.$|^\.\.$/ } readdir $dh;
returns 1650.
>
> Test:
>
> perl -wle '
> $dir = q{/usr/bin};
> opendir $dh, $dir or die qq{opendir $dir: $!};
> print qq{$_\t}, -f qq{$dir/$_} for (sort readdir $dh)[0..10]
> '
>
>
--
Mathew
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>