Re: Pragmas use strict and use warnings
- From: mritty@xxxxxxxxx (Paul Lalli)
- Date: Wed, 31 Oct 2007 04:17:33 -0700
On Oct 30, 5: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, but generally it's better to present use
strict 'vars' as a way to force oneself to declare variables.
I would agree, if the resulting error message was something along the
lines of "Undeclared variable $foo while using strict", but it's not.
The error message is "global variable $foo must be fully qualified
while using strict vars". When a new Perl programmer sees that
message, if all they know about using strict is that it "forces you to
declare your variables", this error message is meaningless, and
frequently leads to the wrong solution. They either fully qualify it,
or they stick an 'our' in front of it.
Tell newbies what 'strict' actually does, and the error message makes
sense, and they know what they did wrong and how to fix it.
Paul Lalli
.
- 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: Pragmas use strict and use warnings
- Next by Date: impatient DBI query
- Previous by thread: Re: Pragmas use strict and use warnings
- Next by thread: problem in returning the hash reference
- Index(es):
Relevant Pages
|