When I run the following code with the Warning flag I get the following
message:
Variable "%hash" will not stay shared....
Here is my code:
#trying to sort a Hash by Value
use strict;
my @list = ('apple',12, 'peach', 2, 'pear', 45);
&function_one(@list);
sub function_one {
my %hash = @_;
my @newhash = sort by_value keys %hash;
foreach(@newhash) {
print "$_\t\t$hash{$_}\n";
}
sub by_value{
$hash{$a} <=> $hash{$b};
}
}
I guess it is complaining that I am calling a subroutine within a subroutine
and the variable %hash can't be shared. But the code still works. I found
out that if I replace the "MY" in front of %hash with "OUR", the warning
will go away. Local() will also work but since I have "use strict" it
FORCES me to use my(). So how do we deal with calling subroutines within a
subroutine in terms of sharing variables?
any suggestions?
Charles
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com