perl.beginners
[Top] [All Lists]

Re: Curly braces and the logic of PERL

Subject: Re: Curly braces and the logic of PERL
From: Brian
Date: Mon, 27 Oct 2008 17:51:48 +0000
Newsgroups: perl.beginners


John W. Krahn wrote:
Brian wrote:
Hello

Hello,

<snip>

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';}

The first } is the end of the while block and the second } is the end of the anonymous subroutine and ", '/test';" is the second argument to find() and not part of the anonymous subroutine. Another way to write that is:

sub wanted {
    return unless -f;
    open my $FH, '<', $_ or die "Cannot open '$_' $!";
    while ( <$FH> ) {
        /\Q$string/ && print $REPORT "$File::Find::name\n" and return;
        }
    }

find \&wanted, '/test';



John

Thanks John, things are starting to get clearer :-)

regards
Brian

<Prev in Thread] Current Thread [Next in Thread>