RE: Trouble with variable scoping



Roman Daszczyszak wrote:

: In my perl script, I have a "global" variable called
: @excludedIPAddresses, declared at the top of the script using
: my.

That sounds like a bad idea, but go on.


: When I run this, I get an error "Can't localize lexical
: variable". I understand that it's because the variable is
: declared using "my"; what I don't understand is why, or what I
: should declare the variable as, since if I leave out "my" I get
: an error using "use strict".

Don't use local() in this circumstance.

sub ExcludeIPAddress {
my $ipAddress = shift;
my $subnet = shift;

return scalar grep /$ipAddress/,
@excludedIPAddresses,
$subnet->broadcast(),
$subnet->base();
}



HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer

254 968-8328

Don't tread on my bandwidth. Trim your posts.

.



Relevant Pages

  • RE: Trouble with variable scoping
    ... Subject: Trouble with variable scoping ... In my perl script, I have a "global" variable called ... @excludedIPAddresses, declared at the top of the script using ... I only know of using 'my' to declare variables (which are ...
    (perl.beginners)
  • Trouble with variable scoping
    ... In my perl script, I have a "global" variable called ... # User-configured variable declarations ... @excludedIPAddresses can only handle specific IP addresses for now ... # Globals: ...
    (perl.beginners)