Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: "return" to break out of a loop

by 5mi11er (Deacon)
on May 13, 2008 at 14:40 UTC ( [id://686279]=note: print w/replies, xml ) Need Help??


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

Yes, you're being overly fussy. This type of construct is very common because it is both clear and more efficient than say setting a "truth flag" then having to finish examining the rest of the values.

The other way to write this and to keep efficiency is something like:

my($flag)=0; foreach my $enum( @$enums) { if ( $check_type eq $enum) { $flag = 1; last; } } return $flag;
Which is about twice as long. So, I personally like the 4 line version better.

-Scott

Update: I like anonymous monk's one line grep version above even more :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found