FWIW using a label can have unwanted global side-effects, because a nested sub could have a goto _;
some experiments:
$ perl -MO=Concise,ret,empty,label -e'sub ret {return}; sub empty {()} +; sub label {LABLE:};' main::ret: 4 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->4 1 <;> nextstate(main 2 -e:1) v ->2 3 <@> return K ->4 2 <0> pushmark s ->3 main::empty: 7 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->7 5 <;> nextstate(main 4 -e:1) v ->6 6 <0> stub P ->7 main::label: 9 <1> leavesub[1 ref] K/REFC,1 ->(end) 8 <;> nextstate(LABLE: main 6 -e:1) P ->9 -e syntax OK
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
¹) jdporter pointed out: you say "last statement", but you mean "last expression evaluated". Not the same thing!
well yes not every statement is an expression leading to a value, and it's the last in the current code flow which counts (think if/else), not in the sub.
That's what the docs say:
If no return is found and if the last statement is an expression, its value is returned. If the last statement is a loop control structure like a foreach or a while, the returned value is unspecified. The empty sub returns the empty list
In reply to Re^2: Label makes a sub to return empty list -- "secret"? documented?
by LanX
in thread Label makes a sub to return empty list -- "secret"? documented?
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |