Keep It Simple, Stupid | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Greetings Monks,
My question is related to this post next'ing out of a "foreach" loop within a subroutine. Take this code:
I was expecting perl to throw me an error for using next to return from a sub{} , however it doesn't happen so. (although I could get a warning, if I use the -w flag). Also next, says:
"next" cannot be used to exit a block which returns a value such as "eval {}", "sub {}" or "do {}"...
My question is: why this behaviour ? what is the logic behind it ? wouldn't it be beneficial if the interpreter threw a error for invalid use of next, in this case ? (I have tested this code under perl v5.8.6)
In reply to Exiting subroutine via next by InfiniteLoop
|
|