Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How exactly does no work?

by PerlOnTheWay (Scribe)
on Feb 16, 2012 at 11:19 UTC ( #954194=perlquestion: print w/ replies, xml ) Need Help??
PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:

use strict; + use warnings; sub c { no warnings; print $d; } sub a{ no warnings; print $b; c; } a();

The first Use of uninitialized value can be fixed by no warnings, but the second is reporting a fatal error,why?

Comment on How exactly does no work?
Download Code
Re: How exactly does no work?
by moritz (Cardinal) on Feb 16, 2012 at 11:24 UTC

    Warnings are not errors, and errors are not warnings.

    The fatal error comes from strict because you didn't declare $d. And because it comes from strict and not warnings, no warnings; has no effect on it. While you can say no strict 'vars';, it's much better to just declare $d with my.

      Why is it NOT fatal when I print $b; in sub a?

      Is no a run time or compile time thing?

      And it seems it's only effective in the current block, not in outer or inner block

        Minimal reference to the docs -- say perldoc -f no -- would put you on the path to answers. See also, as the docs suggest, use.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://954194]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-08-31 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls