Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Difference between 'use warnings' and '-w' switch

by muntfish (Chaplain)
on Jan 11, 2006 at 12:04 UTC ( [id://522411]=perlquestion: print w/replies, xml ) Need Help??

muntfish has asked for the wisdom of the Perl Monks concerning the following question:

I need a bit of clarification on the differences between saying use warnings; and putting -w on the command line. I thought they were the same.

My code starts:

use strict; use warnings; use Net::FTP;

When I put -w on the command line, code within Net::FTP throws a warning at line 716 when trying to send a file. This is version 2.70 of Net::FTP and when I look at the source, it is trying to do -f $loc when $loc has never been assigned to (the warning is "uninitialised value in -f"). So the warning is genuine, nothing I can do to prevent it.

The reason behind the error is not really relevant here, but I'm wondering why if I just say "use warnings" without the -w switch, this warning is not reported?

Thanks.


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re: Difference between 'use warnings' and '-w' switch
by dave_the_m (Monsignor) on Jan 11, 2006 at 12:23 UTC
    use warnings is lexically scoped: it only enables warnings in the current block of code. -w is global: it enables warnings in all code, including Net::FTP.

    Dave.

Re: Difference between 'use warnings' and '-w' switch
by northwind (Hermit) on Jan 11, 2006 at 12:25 UTC

    -w turns warnings on for the entire program, while use warnings; only turns on warnings for the current /scope|module|file/.

    Update:Meh, late on the post.  First post describes it better (if better is defined as using Perl compliant language :) ).

Re: Difference between 'use warnings' and '-w' switch
by monkey_boy (Priest) on Jan 11, 2006 at 12:29 UTC
    this is the full line from that module:
    my $size = do { local $^W; -f $local && -s _ };

    note, he locally turns off the warnings , (old style -w/$^W warnings);


    This is not a Signature...

      Thanks - actually the line in my version (2.70) is:

      $ftp->_ALLO(-s _) if -f $loc;

      And since there is no code to initialise $loc before this line, it will always produce a warning. It looks like this has been fixed in later versions (I checked 2.75 from CPAN) - it has been changed to the line you describe (note $local not $loc).

      Thanks.


      s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://522411]
Approved by Corion
Front-paged by Anneq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found