Gossamer Forum
Home : General : Perl Programming :

variable masks earlier declaration

Quote Reply
variable masks earlier declaration
Hi,

appreciate if anyone can explain this error message:

"my" variable $sql masks earlier declaration in same scope at C:/Inetpub/wwwroot/cgi-bin/somefile.pl line 45



Quote Reply
Re: [matgos] variable masks earlier declaration In reply to
Hi,

Basically, it means you have already pre-defined a variable. For example:

Code:
my $test = 1;

my $test = 5;

...would give the same error message (because you are defining the same variable more than once Smile)

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] variable masks earlier declaration In reply to
Not define per se, but declare. The variable was redeclared in the same scope. Not an error per se, but a warning. However, very common. I used to do this a fair bit when I originally started to code in 'strict' a number years back.

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [dan] variable masks earlier declaration In reply to
Hi,

Yup, easily done :) Most of the time, you can get away with it (unless you are "overwriting" something you actually didn't wanna overwrite =))

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] variable masks earlier declaration In reply to
Been mostly coding in PHP lately, but I believe if run with -w switch (e.g., #! /usr/bin/perl -w), warning messages like this will display. Or better, use warnings;

----
Cheers,

Dan
Founder and CEO

LionsGate Creative
GoodPassRobot
Magelln
Quote Reply
Re: [Andy] variable masks earlier declaration In reply to
Thanks.