As an aside, note that conditional creation of a variable is "allowed" in the sense that it is not a syntactic error

Not really a syntax error, no, but:

$ perl -wMstrict -Mdiagnostics -e 'my $x if 0' Deprecated use of my() in false conditional. This will be a fatal erro +r in Perl 5.30 at -e line 1 (#1) (D deprecated) You used a declaration similar to my $x if 0. Ther +e has been a long-standing bug in Perl that causes a lexical variabl +e not to be cleared at scope exit when its declaration includes a fa +lse conditional. Some people have exploited this bug to achieve a kin +d of static variable. Since we intend to fix this bug, we don't want p +eople relying on this behavior. You can achieve a similar static effect + by declaring the variable in a separate block outside the function, e +g sub f { my $x if 0; return $x++ } becomes { my $x; sub f { return $x++ } } Beginning with perl 5.10.0, you can also use state variables to ha +ve lexicals that are initialized only once (see feature): sub f { state $x; return $x++ } This use of my() in a false conditional has been deprecated since Perl 5.10, and it will become a fatal error in Perl 5.30.

See also #133543.


In reply to Re^3: First attempt at bringing in file for input/output by haukex
in thread First attempt at bringing in file for input/output by catfish1116

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.