in reply to Re: Label makes a sub to return empty list -- "secret"? documented?
in thread Label makes a sub to return empty list -- "secret"? documented?
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Label makes a sub to return empty list -- "secret"? documented?
by Jenda (Abbot) on Sep 11, 2025 at 17:43 UTC | |
by LanX (Saint) on Sep 11, 2025 at 23:04 UTC | |
by Jenda (Abbot) on Sep 12, 2025 at 11:33 UTC | |
by LanX (Saint) on Sep 13, 2025 at 13:38 UTC |