Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: "return" to break out of a loop

by 5mi11er (Deacon)
on May 13, 2008 at 14:40 UTC ( #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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://686279]
[marioroy]: It's a quoting issue inside qx. It's File::Find or qx. LA chooses qx. Almost there.
[marioroy]: Also \"%S\\\n\" oh my, not fun.
[Discipulus]: good night folks
[marioroy]: I will make a mp3info script that takes the -p "%S\n" args and test qx. I'm on the road, so will come back.
[marioroy]: All because File::Find is not fun for LA.
[marioroy]: good night Discipulus.
[Discipulus]: perl dreams to you all

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-04-23 21:20 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.