Rob Dixon wrote: >Jan Eden wrote: >> >>Rob Dixon wrote: >> >>>John W. Krahn wrote: >> >>>>use File::Find; local ( $^I, @ARGV ) = ''; find( { no_chdir => 1, >>>>wanted => sub { -f and push @ARGV, $_ } }, './mydir' ); >>>>s/foo/bar/g, print while <>; >>> >>>Thanks John. >>> >>>I missed the 'has subdirectories'. >>> >> >>I did not and came up with a similar (but simpler) idea: >> >>use File::Find; local $^I = ''; find( { sub { push @ARGV, $_ if -f >>}, 'dir' ); while (<>) { s/foo/bar/g; print; >>} >> >>I forgot to empty @ARGV, and I see why it's necessary. But I do not >>understand John's anonymous subroutine as find's first argument. >>Could someone explain it in a little more detail? > >Hi Jan. > >If you think about it, you'll see that it's an anonymous hash > >{ .. } > >not an anonymous subroutine > >sub { .. } > >In the simple case where you don't need any special options you can >pass a code reference as the first parameter to 'find' which is used >as the 'wanted' subroutine. John wanted 'no_chdir', so he had to use >the full form. This option prevents file() from doing a chdir to the >the current directory ($File::Find::dir) before it calls the 'wanted' >routine.
I will never learn: After your hint to a "full form", I checked perldoc File::Find and learned about the options. So far, I had only read the Camel's short description of File::Find. Thank you, Jan -- There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>