in reply to $_ and nested while loops w/angle operator

Or, that wonderful scalar range operator again...

my %data = (); my $query; while (<FH>) { if (my $result = /^"\@QUERY:(.*?)"$/ .. /^"\@ENDQUERY"$/) { next if $result =~ /E/; if ($result == 1) { $query = $1; next; } push @{$data{$query}}, $_; } }

Replies are listed 'Best First'.
Re: Re: $_ and nested while loops w/angle operator
by eric256 (Parson) on Apr 05, 2004 at 23:40 UTC

    My head nearly exploded looking over that. Could you just explain a little of the logic there? or point me to the needed resource?

    Update: After RTFM I learned about the .. operator. Which i had read before but seeing it in this context helped bring it to light. However i'm very confused by next if $result =~ /E/; Why do you care if it has a big E in it? or did I miss something else?


    ___________
    Eric Hodges
      The '..' and '...' range operators return a number with 'E0' appended to it when the second condition matches (indicating that you are at the End of your range). That way you can tell if it is the last line with /E/ or /E0/ (e.g. if you only want the stuff in between the start and end markers), and the return value is still valid as a number. See perlop.