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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |