I have following code in Perl where a hash reference is passed from main function to func1 and then to func2. In func2 hash is updated. I want to access the updated hash in main function. Also there is a while loop in main function and i am expecting the hash should be updated during every iteration. The code might not look logical, but i have just written the skeleton of the code. I always get empty hash when i try to print the hash in main function
sub main {
my %hash1;
while (some condition)
{
my $i=0;
if($i==0)
{
func1($i,\%hash1);
$i=1;
}
else
{
func1($i,\%hash1);
$i=0;
}
}
foreach my $a (keys %hash1)
{
print "$hash1{$a}";
}
}
sub func1
{
my ($i,$hash1)=@_;
----
if($i==0)
{
func2($hash1);
}
}
sub func2
{
my ($hash2)=@_;
$hash2->{key1}=1;
$hash2->{key2}=2;
}