in reply to Python gave me a colonic (solved - brainfart)
> No warnings, no syntax errors, nothing except the (seemingly) impossible behavior
Like already explained, because of the colon else: becomes a label, so it's quite possible.
BUT it's good practice - or at least my practice - to only use uppercase WORDS for labels.
So a linter could easily catch this already.
Furthermore it's pretty hard to use a keyword like else as a label b/c next else; and alike would be syntax errors.
To make it work you'd need to hide it inside an expression like with goto ("else")[0];
So yes, there are potential ways to catch unwanted labels and warn about this. (lowercase and or reserved keyword)
POC: this runs fine
use strict; use warnings; my $x; else: { print ++$x; redo ("else")[0] if $x <3; }
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
in hindsight I realized that putting the label into quotes is already enough
redo "else" if $x <3;
|
|---|