Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: How exactly does no work?

by PerlOnTheWay (Scribe)
on Feb 16, 2012 at 11:37 UTC ( #954201=note: print w/replies, xml ) Need Help??

in reply to Re: How exactly does no work?
in thread How exactly does no work?

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

Replies are listed 'Best First'.
Re^3: How exactly does no work?
by ww (Archbishop) on Feb 16, 2012 at 11:40 UTC
    Minimal reference to the docs -- say perldoc -f no -- would put you on the path to answers. See also, as the docs suggest, use.

      Okay, let’s just cut to the chase here.   use is somewhat of an “overloaded” construct in Perl.   It can be employed to reference an outside module (use foo;), or as a pragma to request certain compile-time behavior (use strict;).

      When I typed in what you entered as a “one-liner,” I got various compilation errors (as I should have).   There are several things quite wrong with the code ... undeclared variables, parentheses, and so forth.   On my system it will not compile at all.   If I add my ($b, $d); I get no output at all because of course everything is now undef.   So I am just going to set that (non-)example completely aside.

      no warnings; like its brother use warnings;, is a compile-time directive.   It instructs Perl to behave in different ways when compiling your source-code into its internal form for execution.   One form countermands the other.   I do not profess to know the whys and wherefores of these things because the one thing that I do know is how to use them correctly, which IMHO is:

      • At the top of every Perl program that you write, use strict; use warnings;.
      • In the extremely rare case where you are forced to do something that these declarations would prevent, and you cannot find another way (translation:   you haven’t looked hard enough yet, e.g. at UNIVERSAL), then you should bracket the smallest portion of code necessary.   Insert no warnings;, then do the minimal amount of work, then immediately use warnings; again ... having first inserted a prodigious comment explaining exactly why you had to do this.

        use is somewhat of an “overloaded” construct in Perl. It can be employed to reference an outside module (use foo;), or as a pragma to request certain compile-time behavior (use strict;).

        I think that explanation confuses more than it enlightens. In both cases (pragma and module), use does the same thing:

        BEGIN { require '': 'Module'->import; };

        It always performs the require (modulo Perl's internal cache of what it's already loaded) and it always performs the import (modulo use Foo ();). use has no idea of whether what it's loading is a pragma. That part's up to the loaded thing's import() method.

      perldoc -f no doesn't tell the answer.
        Oh? For me, it provides the start I promised:
        C:\>perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +86-multi-thread (with 1 registered patch, see perl -V for more detail) .... Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at, the Perl Home Pa +ge. C:\>perldoc -f no no MODULE VERSION LIST no MODULE VERSION no MODULE LIST no MODULE no VERSION See the "use" function, of which "no" is the opposite. C:\>perldoc -f use use Module VERSION LIST use Module VERSION use Module LIST use Module use VERSION Imports some semantics into the current package from the n +amed ....
        Maybe a problem with your installation? What output do you get from perldoc -f no?

        Ronald Fischer <>
         [doc://no] no

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://954201]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-04-23 12:00 GMT
Find Nodes?
    Voting Booth?