develooper Front page | perl.perl5.porters | Postings from October 2011

[perl #102464] is warning valid?

Thread Next
From:
Father Chrysostomos via RT
Date:
October 29, 2011 09:35
Subject:
[perl #102464] is warning valid?
Message ID:
rt-3.6.HEAD-31297-1319906148-21.102464-15-0@perl.org
On Sat Oct 29 04:59:08 2011, LAWalsh wrote:
> To be honest, I'm not even sure this is a real bug, or is be
> design, but it seems counterintuive.
> 
> if I test a variable for being 'defined' :
> 
> 	if (defined($foo)) {
> 		print "foo=$foo\n";
> 	}
> 
> 
> 	Should I, even under strict (which is the case), get:
> 
> Global symbol "$foo" requires explicit package name at -e line 3.
> Execution of -e aborted due to compilation errors.
> 
> 
> I can understand *why* it happens, but *should* it happen?
> I.e. in the above example, that "$foo" isn't defined is not a
> 'design error' and it not being defined is checked for, preventing
> it's use.  So should it cause a "parse-time" error?

To respond to the main point of this report:  The purpose of strict vars
is to avoid typos.  It is a compile-time pragma that does not allow you
to mention variables that have not been declared within the current
scope or imported into the current package.

So, yes, it is behaving as designed.

--

Father Chrysostomos


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About