Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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

by Anno (Deacon)
on Feb 16, 2007 at 16:28 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://600471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found