Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-01-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?