"...
Unlike 'my', however, it is a permanent
package variable and its value will be retained across calls to a
subroutine ..." --Rob
Hi Rob,
So does this make it equivalent to a C-style static variable?
I've been trying to test it, and it seems to be impossible to even declare it using
strict. When I try to declare a variable as local, I get an error telling me that the
global symbol needs an explicit package name. When I try to modify an existing
variable, I get an error saying that I can't modify a lexical variable.
Without strict, I have yet to find any configuration that would actually retain value
between calls to a function.
Can you show any examples of local at work--preferably using strict?
Thanks,
Joseph
I do have a little demo for the our and my scoping, about the way I would use them. I
actually couldn't detect any difference when declared in the global scope, so I take
the our declaration as a comment, to remind me that I've done something dumb by
declaring in the global context. Essentially, I would say that visibility protection
comes down to the location of the declaration.
#!/usr/bin/perl -w
#use strict;
our $FirstName = "Robert";
FeedSub();
sub FeedSub {
$MiddleName = "Joseph";
my $LastName = "Newton";
for (1...4) {
TestIt($LastName, $MiddleName);
print "$LastName\n";
print "$FirstName\n";
print "$MiddleName\n";
}
}
sub TestIt {
my ($LastName, $MiddleName) = @_;
print "$LastName\n";
$MiddleName .= '_';
$FirstName .= '_';
print "$FirstName\n";
print "$MiddleName\n";
print "$LastName\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]