On Mon Oct 27 2008 @ 5:05, Brian wrote:
> An example of something confusing me is in the sample below
> find sub {
> return unless -f;
> open my $FH, '<', $_ or die "Cannot open '$_' $!";
> while ( <$FH> ) {
> /\Q$string/ && print $REPORT "$File::Find::name\n" and
> return;
> }}, '/test';
>
> Why isn't the last line
> }, '/test';}
Does this make it any better?
find sub {
return unless -f;
open my $FH, '<', $_ or die "Cannot open '$_' $!";
while ( <$FH> ) {
/\Q$string/ && print $REPORT "$File::Find::name\n" and return;
} # close the while loop
}, '/test'; # close the sub and run the subroutine on the directory '/test'
The first brace closes the while loop. The second closes the subroutine.
The subroutine itself is an anonymous one with the directory to process
placed immediately following.
In a nutshell, instead of this:
find( \&subroutine, '/test' );
you can write this:
find sub { stuff; }, '/test';
Hope this helps, T
pgpGz4ZdonQ25.pgp
Description: PGP signature
