S
sam
Hi,
I m trying to pass the reference of a hash variable to subroutine's
subroutine, but I found no record being passed to the function. Here is
the actual code:
#!/usr/bin/perl
sub print_hashes
{
local ($hash) = @_;
pass_one_more_level(\%hash);
#foreach my $name ( keys(%hash) ) {
# print "$name: ", join( "--", %{$hash{$name}} ), "\n";
#}
}
sub pass_one_more_level
{
local ($hash) = @_;
foreach my $name ( keys(%hash) ) {
print "$name: ", join( "--", %{$hash{$name}} ), "\n";
}
}
sub main {
local %hash1 = ('sales_subtotal'=>100);
local %hash2 = ('sales_subtotal'=>150);
local %hash3 = ('sales_subtotal'=>500);
local %myhash_A = (heading1 => {sales_subtotal => 10},
heading2 => {sales_subtotal => 15},
heading3 => {sales_subtotal => 50});
local %myhash_B = (heading1 => %hash1,
heading2 => %hash2,
heading3 => %hash3);
print_hashes(\%myhash_A);
print_hashes(\%myhash_B);
}
main();
What is the correct way for fixing this error?
Thanks
Sam
I m trying to pass the reference of a hash variable to subroutine's
subroutine, but I found no record being passed to the function. Here is
the actual code:
#!/usr/bin/perl
sub print_hashes
{
local ($hash) = @_;
pass_one_more_level(\%hash);
#foreach my $name ( keys(%hash) ) {
# print "$name: ", join( "--", %{$hash{$name}} ), "\n";
#}
}
sub pass_one_more_level
{
local ($hash) = @_;
foreach my $name ( keys(%hash) ) {
print "$name: ", join( "--", %{$hash{$name}} ), "\n";
}
}
sub main {
local %hash1 = ('sales_subtotal'=>100);
local %hash2 = ('sales_subtotal'=>150);
local %hash3 = ('sales_subtotal'=>500);
local %myhash_A = (heading1 => {sales_subtotal => 10},
heading2 => {sales_subtotal => 15},
heading3 => {sales_subtotal => 50});
local %myhash_B = (heading1 => %hash1,
heading2 => %hash2,
heading3 => %hash3);
print_hashes(\%myhash_A);
print_hashes(\%myhash_B);
}
main();
What is the correct way for fixing this error?
Thanks
Sam