Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Get out of "For Loop"!

by girarde (Friar)
on Oct 13, 2010 at 19:08 UTC ( #865137=note: print w/ replies, xml ) Need Help??


in reply to Get out of "For Loop"!

This being Perl there are several right ways. Another one would be:

for (my $i = 0; $i < @{$data}; $i++) { my $email = $data->[$i]{'email'} || ''; my $name = $data->[$i]{'name'} || ''; unless ($email) { bad("No email address."); last; }else{ good("Email found."); } }

This does not test for validity of the email, of course, but presumably you do that elsewhere. And presumably the good and bad subroutines are defined somewhere.


Comment on Re: Get out of "For Loop"!
Select or Download Code
Replies are listed 'Best First'.
Re^2: Get out of "For Loop"!
by morgon (Deacon) on Oct 13, 2010 at 19:26 UTC
    But to quote from one of the holy books (Perl Best Pratices, Chapter 6.4):
    Don't use unless or until at all.

    So instead if unless($email) rather use if(! $email)

      Damian is sometimes wrong. Shhh! Don't tell anyone.

      I prefer unless() as a suffix. I do agree that an unless() block should not have an else ... negating the negation warps my mind this early on a Monday morning. But it doesn't need one, since the next / last goes to the next iteration of the loop.

      As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2015-07-28 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls