Re: Pragmas use strict and use warnings
- From: nobull67@xxxxxxxxx (Nobull67@xxxxxxxxx)
- Date: Wed, 31 Oct 2007 08:38:42 -0000
On Oct 30, 9:24 pm, Je...@xxxxxxxxxxx (Jenda Krynicky) wrote:
On 30 Oct 2007 at 10:22, Paul Lalli wrote:
On Oct 30, 11:15 am, chas.ow...@xxxxxxxxx (Chas. Owens) wrote:
On 10/30/07, Kaushal Shriyan <kaushalshri...@xxxxxxxxx> wrote:
snip> Whats the exact purpose of use strict
snip
The strict pragma has three effects (unless modified by arguments):
1. most variables must be declared (there are some exceptions)
This is a common misperception. use strict 'vars' in fact does not
require anything to be declared. All it requires is that global
variables must be fully qualified. You cannot use the short-name of
globals that belong to the current package.
<snipped>
With strict enabled, the only way to use a short-name of a variable is
to declare a lexical of that name (the right choice) using 'my', or to
disable strict 'vars' on a variable-by-variable case using 'our' (the
wrong choice). This is what leads people to assert "use strict forces
you to declare your variables".
Technicaly you are right,
Actually he's subtly wrong. But that's not important.
but generally it's better to present use
strict 'vars' as a way to force oneself to declare variables. It may
not be exactly what it does, but it's why it exists.
I prefer to think of (and initially describe) 'strict' as switching
off three optional (and only occasionally useful) extensions to the
language that you wouldn't want Perl to accidentally think you were
trying to use when you make a mistake.
As users become more experienced they will reach a point where these
extensions may be useful to them. And at that point, and only at that
point, is it worth trying to understand in detail what 'no strict'
does.
.
- References:
- Pragmas use strict and use warnings
- From: Kaushal Shriyan
- Re: Pragmas use strict and use warnings
- From: Chas. Owens
- Re: Pragmas use strict and use warnings
- From: Paul Lalli
- Re: Pragmas use strict and use warnings
- From: Jenda Krynicky
- Pragmas use strict and use warnings
- Prev by Date: Re: problem in returning the hash reference
- Next by Date: Re: Pragmas use strict and use warnings
- Previous by thread: Re: Pragmas use strict and use warnings
- Next by thread: Re: Pragmas use strict and use warnings
- Index(es):
Relevant Pages
|