Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Closure warning with Perl 5.14?

by BerntB (Deacon)
on May 19, 2011 at 09:19 UTC ( #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
Node Status?
node history
Node Type: note [id://905643]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-12-05 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (63 votes). Check out past polls.

    Notices?