http://www.perlmonks.org?node_id=600471


in reply to Re: How to get ($1, $2, ...)?
in thread How to get ($1, $2, ...)?

Reproducing a bit of your code:
my @answers; while (my $line = <DATA>){ for my $re (@res){ my @results; if (@results = $line =~ /$re/){ push @answers, ["@results"];
Why the quotes around @results? They weren't in the version that produced the output you're showing.
} } }
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
    Oh, or even
    # ... push @answers, grep @$_, map [ $line =~ $_], @res; # ...
    instead of the for loop over @res.

    I realize I'm expanding on a non-solution to the original question. It's art for art's sake, if that's allowed.

    Anno