To elaborate more ...

> 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

update

in hindsight I realized that putting the label into quotes is already enough

redo "else" if $x <3;


In reply to Re: Python gave me a colonic by LanX
in thread Python gave me a colonic (solved - brainfart) by bobn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.