Perl Programming Help:
Re: [PerlUser12] Meaning of -w and qw:
Oct 27, 2012, 7:25 AM
The -w switch enables warnings. It is described in perlrun, which is accessed via the perldoc command.
Re: [PerlUser12] Meaning of -w and qw
or online at: http://perldoc.perl.org/perlrun.html
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:
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.
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. http://perldoc.perl.org/perlop.html
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)
Post edited by FishMonger
(Veteran) on Oct 27, 2012, 7:27 AM
Post edited by FishMonger
(Veteran) on Oct 27, 2012, 7:28 AM