i have a question for the following perl code,  by changing the value
in %h3, the script also changes the value for %h4, I vaguely
understand it is because %h3's key is reference to %h2, %h2's key is
reference to %h1,

so by changing value in %h3, the script also changes the value for %h4,
I was wondering if there is a way to address this problem, I don't
want by changing $h3{k3}{k2}{k1} = "v2", %h4 also got changed.

Thank you list for any pointers, I am absolute newbie and I am learning..       

my %h1 = ( k1 => "v1"  );               
my %h2 = ( k2 => \%h1  );                       
my %h3 = ( k3 => \%h2  );                               

my %h4 = %h3;                                           

print "h3\n";                                           
foreach my $i ( keys %h3 ) {
 print "$i => $h3{$i}\n";
 foreach my $j (keys %{$h3{$i}}) {
  print "  $j => $h3{$i}{$j}\n";
  foreach my $k ( keys %{$h3{$i}{$j}}) {
    print "    $k => $h3{$i}{$j}{$k}\n";
  }
 }
}                                                                       

$h3{k3}{k2}{k1} = "v2";                         

print "h4\n";
foreach my $i ( keys %h4 ) {
 print "$i => $h4{$i}\n";
 foreach my $j (keys %{$h4{$i}}) {
  print "  $j => $h4{$i}{$j}\n";
  foreach my $k ( keys %{$h4{$i}{$j}}) {
    print "    $k => $h4{$i}{$j}{$k}\n";
  }
 }
}

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to