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;


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]
  '


>>>   my @filenames = grep -f, <$processDir/*> ;
>>>
>>> (but that @filenames uses more memory).
>>
>> It uses more memory because the full pathname is in each element.
>>
> I figured that was why you brought it up earlier so I have it
> prepending the directory name in the foreach loop that runs the stat.
> This way I'm not saving the full path anywhere and only using it long
> enough to stat the file.

Yes. The difference is that the glob-variant (the one looking like
<$dir/*>) contains the full pathnames, and the readdir-variant just the
basenames.

-- 
Affijn, Ruud

"Gewoon is een tijger."



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to