You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when using match::simple::sugar (with Data::Enum that now supports match::simple !),
when nesting the switch for () { when ..., then{}; ...} non-looping loop block
within an outer for(), foreach() or while(<>){} 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.
the outer loops must use a named loop variable, or (minimally invasive) have a local my $line=$_; just before the SWITCH: for when, and any and all implicit m{}, //, etc or explicit references to $_ must be changed to $line =~ m{}.
outer and inner loops need LINE: while(<>){...} and SWITCH: for ($STATE){when .. statement labels, as when...then will do next on the inner for as if it were a loop, so script's own loop control next, redo, last must name next LINE;.
to avoid a flurry nay blizzard of Exiting subroutine via next at warnings on STDERR, must insert no warnings 'exiting'; after SWITCH: 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 the then {block} ?
(Near as i can tell, there's no danger of an innermost loop inside the then{} clause having a problem, as the hidden next SWITCH by the when occurs after the then{} anon sub returns to when, if i don't next LINE; out of it.)
The text was updated successfully, but these errors were encountered:
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. 🤣 )
when using
match::simple::sugar
(withData::Enum
that now supportsmatch::simple
!),when nesting the switch
for () { when ..., then{}; ...}
non-looping loop blockwithin an outer
for()
,foreach()
orwhile(<>){}
actual loopas 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;
.flurry nayblizzard ofExiting 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.)The text was updated successfully, but these errors were encountered: