Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How does next label work?

by LanX (Canon)
on Jan 06, 2013 at 09:49 UTC ( #1011865=note: print w/ replies, xml ) Need Help??


in reply to How does next label work?

Naked blocks are documented as being internally implemented as loops which are only executed once.

next is a loop control which reevaluates the condition, which is false now.

It's no goto, you can only use if for lables just in front of loop-starts, OTOH gotos can jump to any lables in the same scope.

For your purpose better try redo

> perl { print $x++; redo if $x<6; } __END__ 012345
or real gotos

> perl X: { print $x++; goto X if $x<6; } __END__ 012345

Cheers Rolf

UPDATES:

)from perlsyn

Basic BLOCKs A BLOCK by itself (labeled or not) is semantically equivalent t +o a loop that executes once. Thus you can use any of the loop control statements in it to leave or restart the block.


Comment on Re: How does next label work?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2015-07-31 11:01 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 (276 votes), past polls