Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: use strict

by KM (Priest)
on Jun 07, 2000 at 19:17 UTC ( [id://16875]=note: print w/replies, xml ) Need Help??


in reply to use strict

From perlrun:

-w
prints warnings about variable names that are mentioned 
only once, and scalar variables that are used before being 
set. Also warns about redefined subroutines, and references 
to undefined filehandles or filehandles opened read-only 
that you are attempting to write on. Also warns you if you 
use values as a number that doesn'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. 


You can disable specific warnings using __WARN__ hooks, as 
described in perlvar and perlfunc. See also perldiag and 
perltrap. 

The strict pragma is used to restrict unsafe constructs. There are 'refs', 'vars', and 'subs'. You can simply do 'perldoc strict' to see the POD, but in a nutshell, 'refs' makes sure you don't use symbolic references, 'vars' ensures you always predeclare your variables (and are declared in scope), and 'subs' makes sure you do not use a bareword unless it is in curlies {}, or is on the left side of =>. Likely, the example code does something that either -w or strict doesn't like. You can turn off one of the three pieces of strict like so:

no strict 'refs';

For example. Sometimes this comes up when some module isn't very strict friendly (sometimes I run across this when using filehandles for certain graphic manipulation modules). If you have warning turned on, and are about to do something that is not -w friendly, you can turn them off with:

$^W = 0;

and back on by setting it back to 1. I hope this quick rundown helps a bit.

Cheers,
KM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://16875]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found