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

[perl #102464] is warning valid?

Thread Next
Father Chrysostomos via RT
October 29, 2011 09:35
[perl #102464] is warning valid?
Message ID:
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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About