Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: How to get ($1, $2, ...)?

by Anno (Deacon)
on Feb 16, 2007 at 16:28 UTC ( #600471=note: print w/replies, xml ) Need Help??

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; } # ...


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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://600471]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2019-07-22 09:47 GMT
Find Nodes?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?

    Results (12 votes). Check out past polls.