Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Closure warning with Perl 5.14?

by BerntB (Deacon)
on May 19, 2011 at 09:19 UTC ( [id://905643]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Closure warning with Perl 5.14?
in thread Closure warning with Perl 5.14?

This complains about uninitialized value (of course), but gives no warning in 5.14.0:

use warnings; use strict; use constant duh => 0; my $y = "X" if duh; sub x{ print $y ? 'Okay' : 'bad'; } x(); print "$y\n";

And no warning even for this:

use warnings; use strict; my $y = "X" if 0; sub x{ print $y ? 'Okay' : 'bad'; } x(); print "$y\n";

Replies are listed 'Best First'.
Re^5: Closure warning with Perl 5.14?
by JavaFan (Canon) on May 19, 2011 at 09:45 UTC
    Yeah, it only warns on my $var if 0, not on my $var = EXPR if COND. I do not know why.

      To allow stuff like the following?

      print(my $x = 1234) if COND;

      Which is to say, they probably didn't want to step on anything that has remote chance of being legit.

        But my $x if COND; doesn't warn either, unless COND is false. Not sure what print(my $x = 1234) if 0; would be good for. Note also that print(my $x = 1234) if COND; does not have a my $x = EXPR if COND subexpression, not even on a textual level.
      That was a hack for getting state variables. So it might be found in code that should use state instead, and won't work as expected in the new versions.
        Yeah, but what is the intention of all other code that uses:
        my $var if COND;
        ? Either the if COND is redundant, because it's always true, or it maybe false and you have the same issue. Also,
        my $var = 0 if 0;
        creates a "state" variable, yet there's no warning.

        Now, I'm usually not a fan of adding a warning for every little thing, but if there's a warning, it shouldn't be inconsistent on when it warns and when it doesn't.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://905643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-30 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found