Jim Gibson <jimsgib...@gmail.com> writes: [...]
>> >> So doesn't it mean that inside find() the program is changing dir >> right along with the search for executable files? That is, every time >> the search digs a directory deeper, `stat' is called inside that >> level. >> >> Isn't that the only way that '$_' would consistently work in stat? >> >> The only way directory + file would work consistently would be >> to only `stat' absolute file names. > > Have you read the documentation for the File::Find module? Before the > find() subroutine is called, the module changes default directory to > the directory containing the file being passed to find(). The name of > the file (without its full path) is in the $_ variable. The full path > name is in $File::Find::name. Therefore, either stat() or > stat($File::Find::name) should work, and your undefined problem lies > elsewhere. I think a found a better way to ensure no unitialized var stuff comes up. I'd like to here if it really is a good way or there are things wrong with it that might bite me. But first... I got to rereading your paragraph above, and kind of wondered if you noticed that what you say there is pretty much a rephrasing of what I had already said to Uri in the three small paragraphs you quoted. Now about this better idea: After going thru this thread I was running the code with some of the improvements suggested, including ditching the original `return unless. And as it turns out, I think that was letting in things like dangling symlinks and maybe some other non -f things... and that was the source of the `uninitialised' warnings. Anyway, first I put that `return' back in and which seemed to cure those warnings. Then I got to thinking about it being a redundancy like John K said, and decided to try a little different way, seems good so far but wondering if more experienced hands would think so: original: my $exe = 33261; my $f = shift; find( sub { return unless -f; $eperm = (stat($File::Find::name))[2]; if ($eperm eq $exe){ print $File::Find::name . "\n"; } }, $f ); ------- --------- ---=--- --------- -------- With some of the suggested modifications and one of my own: my $exe = 0100755; my $d = shift; find( sub { my $eperm; return unless $eperm = (stat)[2]; if ($eperm eq $exe){ print $File::Find::name . "\n"; } }, $d ); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/