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

Re: "return" to break out of a loop

by Anonymous Monk
on May 13, 2008 at 14:33 UTC ( [id://686276]=note: print w/replies, xml ) Need Help??


in reply to "return" to break out of a loop

Hanging loop? In mid-air?
return 1 if grep { $check_type eq $_ } @$enums;

Replies are listed 'Best First'.
Re^2: "return" to break out of a loop
by mscharrer (Hermit) on May 13, 2008 at 14:56 UTC
    Very short but not very efficient because the implicit loop is not aborted at the first successful match. Because grep is returning the number of successful matches in scalar context all list elements are getting checked.
    More efficient would be:
    use List::MoreUtils; return 1 if any { $check_type eq $_ } @$enums;
Re^2: "return" to break out of a loop
by weedom (Acolyte) on May 13, 2008 at 14:41 UTC
    meh. Figure of speech :) Cheers WeeDom

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found