in reply to $_ and nested while loops w/angle operator
To expand upon what diotalevi said... You should do the pattern match inside the inner while loop, not in the conditional itself.
Here's how I'd rewrite your code:
while (<FH>) { if ( /^"\@QUERY:(.*)"/ ) { my $query = $1; while (<FH>) { last if /^"\@ENDQUERY"/; next if $_ eq ''; print $_; push @{$data{$query}}, $_; } } }
Note that this makes a HoA, rather than a HoH. Since the indices of your inner hash were simply sequential integers, an array works just as well, if not better.
PS - You don't need to backwhack quotes inside a /regex/.
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: $_ and nested while loops w/angle operator
by jdporter (Paladin) on Apr 05, 2004 at 21:45 UTC | |
by alienhuman (Pilgrim) on Apr 08, 2004 at 17:06 UTC | |
by jdporter (Paladin) on Apr 08, 2004 at 19:50 UTC |