So the TL;DR version is you wrote instead of and didn't notice the warnings. ;-)

> (It is unfortunate that the subtraction like that only warrants an error at run time and doesn't cause perl to refuse to run the program. I do of course have "use warnings;" and "use strict;" already.)

you can always turn warnings fatal to make Perl die on the spot.

~$ perl -e'use warnings FATAL=>"all"; my $x-1; print "never executed"' Useless use of subtraction (-) in void context at -e line 1. ~$

(use FATAL => "void" to only "fatalize" this particular warning class, see perldiag ° )

That's a good strategy for unit tests anyway where unexpected warnings shouldn't appear. Not sure if I'd like to have this in much longer, hence messier production code.

You can probably also apply Perl::Critic or another linter for this to happen statically at compile time.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

footnote

°) one reason this might not warn at compile time is that you still have a "side effect" in the declaration of my $int - hence this could be intended code (?)

update

I think an optional pragma to make some warning classes die at compile time is worth a consideration.


In reply to Re^3: Interpolate variable into regexp at time of definition rather than execution, as a filter for Path::Iterator::Rule (FATAL warnings) by LanX
in thread Interpolate variable into regexp at time of definition rather than execution, as a filter for Path::Iterator::Rule by ecm

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.