Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Exiting subroutine via next

by ikegami (Patriarch)
on Dec 07, 2006 at 06:38 UTC ( [id://588268]=note: print w/replies, xml ) Need Help??


in reply to Re: Exiting subroutine via next
in thread Exiting subroutine via next

I don't really know how to explain ["next" cannot be used to exit a block which returns a value such as "eval {}", "sub {}" or "do {}"...]

It means next, last and redo ignore do blocks, eval blocks, etc. They will only cause loop blocks and bare blocks to repeat, exit, etc. It makes more sense when you read that same line in the documentation for last, since next doesn't cause a loop to exit.

foreach my $var (1, 2, 3, "skip", 4) { eval { # This block is ignored. if ($var eq "skip") { next; } }; print $var; } print("\n"); foreach my $var (1, 2, 3, "skip", 4) { { # This block exits. if ($var eq "skip") { next; } } print $var; } print("\n");

outputs

1234 123skip4

Replies are listed 'Best First'.
Re^3: Exiting subroutine via next
by geekphilosopher (Friar) on Dec 07, 2006 at 21:32 UTC
    Ah, that makes sense. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found