Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: using next in a nested foreach()

by Codon (Friar)
on Aug 16, 2005 at 17:56 UTC ( [id://484204]=note: print w/replies, xml ) Need Help??


in reply to Re: using next in a nested foreach()
in thread using next in a nested foreach()

This solution, of course, doesn't help with existing deeply nested loops. That's where the labels come in really handy. There is the caveat that the misuse of labels can cause very odd behavior (like the sudden termination of you script) if you are not careful (typos).

Also, to further optimize (typing optimization; not necessarily execution optimization) based on japhy's comment, you could try this instead:

push @results, grep { grep { $1 eq $_ } @two if ( $_ =~ /\(.\)(.+)\(.\)/ ) } @one;
You get to use a nested grep, but you check all values of @two and don't stop when you find a match.

Update: Since grep will localize $_ and I don't need the outer $_ in the inner grep, I optimized away reassigning the outer $_;

Ivan Heffner
Sr. Software Engineer, DAS Lead
WhitePages.com, Inc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-24 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found