in reply to Re: How to get ($1, $2, ...)?
in thread How to get ($1, $2, ...)?
Reproducing a bit of your code:
Why the quotes around @results? They weren't in the version that produced the output you're showing.my @answers; while (my $line = <DATA>){ for my $re (@res){ my @results; if (@results = $line =~ /$re/){ push @answers, ["@results"];
You're also making an unnecessary copy of the array @results. Its scope is the loop body, so you have a new one each time through. Just take the reference:} } }
# ... for my $re (@res){ my @results; push @answers, \ @results if @results = $line =~ $re; } # ...
Anno
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How to get ($1, $2, ...)?
by Anno (Deacon) on Feb 16, 2007 at 21:47 UTC |
In Section
Seekers of Perl Wisdom