Open n1vux opened 2 weeks ago
Additional warning required
that return
in the then {BLOCK}
won't do what is expected, but rather returns from the when-then
anon-sub (lambda).
Would need to return up the call stack to return from my visible sub.
(Instead i just use save a $ret value the way we used to do when one in one out structured programming forbade return from anywhere except the bottom of the subroutine. )
(Aside: Probably helped that I'm old enough to have suffered under that formalism. Which did let us reason over programs, and I have proved several production loops correct according to precondition, invariant, progress, postcondition, which benefited from no early exits / no gotos. But readable code is more useful most of the time. :rofl: )
when using
match::simple::sugar
(withData::Enum
that now supportsmatch::simple
!), when nesting the switchfor () { when ..., then{}; ...}
non-looping loop block within an outerfor()
,foreach()
orwhile(<>){}
actual loop ~as one does~, whether as an event loop or per-line-input loop, there are three implications that should be documented; one of which might be fixable in module code.my $line=$_;
just before theSWITCH: for when
, and any and all implicitm{}
,//
, etc or explicit references to$_
must be changed to$line =~ m{}
.LINE: while(<>){...}
andSWITCH: for ($STATE){when ..
statement labels, aswhen...then
will donext
on the innerfor
as if it were a loop, so script's own loop controlnext
,redo
,last
must namenext LINE;
.Exiting subroutine via next at
warnings on STDERR, must insertno warnings 'exiting';
afterSWITCH: for ($var){
.I would not put the
no warnings
outside the for-when lexical block, so as to not block warnings caused by other errors.It might be practical to inject the
no warnings 'exiting';
into the anon-subs made from thethen {block}
?(Near as i can tell, there's no danger of an innermost loop inside the
then{}
clause having a problem, as the hiddennext SWITCH
by thewhen
occurs after thethen{}
anon sub returns towhen
, if i don'tnext LINE;
out of it.)