Remy Guo wrote:
hi all,
I've got a problem in following script:
sub A {
our %a;
$a{"fred"} = 1;
$a{"bella"} = 2;
...
}
sub B {
if ($fred != $a{"fred"}) {
print "fred failed.\n";
}
if ($bella != $a{"bella"} {
print "bella failed.\n";
}
}
The problem is, I made the hash %a in sub A but in sub B, the value in hash
%a is never read. The declaration "our" seems not effect.
Why?...
The declaration of our is effective. It goes out of scope at the end of
the block containing it. Place it so that its scope contains both
subroutines. Also, it need not be an our variable if it's is only
accessed inside one file.
our %a = ();
sub A {
...
}
sub B {
...
}
Or:
my %a = ();
sub A {
...
}
sub B {
...
}
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/