CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [PerlUser12] Meaning of -w and qw: Edit Log

Veteran / Moderator

Oct 27, 2012, 7:25 AM

Views: 3089
Re: [PerlUser12] Meaning of -w and qw

The -w switch enables warnings. It is described in perlrun, which is accessed via the perldoc command.

c:\>perldoc perlrun 
perlrun - how to execute the Perl interpreter

perl [ -sTtuUWX ] [ -hv ] [ -V[:*configvar*] ]
[ -cw ] [ -d[t][:*debugger*] ] [ -D[*number/list*] ]
[ -pna ] [ -F*pattern* ] [ -l[*octal*] ] [ -0[*octal/hexadecimal*] ]
[ -I*dir* ] [ -m[-]*module* ] [ -M[-]*'module...'* ] [ -f ]
[ -C [*number/list*] ] [ -S ] [ -x[*dir*] ] [ -i[*extension*] ]
[ [-e|-E] *'command'* ] [ -- ] [ *programfile* ] [ *argument* ]...

The normal way to run a Perl program is by making it directly
executable, or else by passing the name of the source file as an
argument on the command line. (An interactive Perl environment is also
possible--see perldebug for details on how to do that.) Upon startup,
Perl looks for your program in one of the following places:


or online at:
Quoted from that doc:


prints warnings about dubious constructs, such as variable names mentioned only once and scalar variables used before being set; redefined subroutines; references to undefined filehandles; filehandles opened read-only that you are attempting to write on; values used as a number that don't look like numbers; using an array as though it were a scalar; if your subroutines recurse more than 100 deep; and innumerable other things.

This switch really just enables the global $^W variable; normally, the lexically scoped use warnings pragma is preferred. You can disable or promote into fatal errors specific warnings using __WARN__ hooks, as described in perlvar and warn. See also perldiag and perltrap. A fine-grained warning facility is also available if you want to manipulate entire classes of warnings; see warnings or perllexwarn.

As mentioned in the doc, it's better to use the warnings pragma instead of the -w switch. You should also be using the strict pragma, so every perl script you write should have these 2 lines after the shebang line.

use strict; 
use warnings;

Those 2 pragmas will point out lots of common mistakes in your code, which aides in writing better quality code.

qw is one of the quote operators and is covered in perldoc perlop under the "Quote and Quote-like Operators " section.

One of the ways it can be used is when assigning values to an array.

my @array = qw( one two three );

(This post was edited by FishMonger on Oct 27, 2012, 7:28 AM)

Edit Log:
Post edited by FishMonger (Veteran) on Oct 27, 2012, 7:27 AM
Post edited by FishMonger (Veteran) on Oct 27, 2012, 7:28 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives