title: Passing a hash to a subroutine without changing it input
body: <p>I'm trying to debug some strange behavior while handling with a hash in <code>Perl</code>.
  I'm passing a hash (not ref) to a subroutine and for some reason it updates it.</p>
  
  <pre><code>some_sub($a,%{$hash});
  sub some_sub {
      my ($a,%hash) = @_;
      my @struct;
      while (my ($dir, $data) = each %hash) {
          foreach my $id (keys(%{$data})) {
              my $entry = $data-&gt;{$id};
              $entry-&gt;{id} = $id;
              my $parent = $data-&gt;{$entry-&gt;{id}};
              unless ($parent) {
                  push @struct, $entry
              } else {
                  push @{$parent-&gt;{children}},$entry;
              }
          }
      }
  }
  my %h= %{$hash};
  print Dumper(\%h);
  </code></pre>
  
  <p>The sub <code>some_sub</code> does change <code>%hash</code> but only for the inner scope, so it should not change the data of the outside <code>%hash</code>. Also, I pass the hash as a hash and not as a hash ref. I suspected the sub <code>some_sub</code> inserts memory addresses into the <code>%hash</code>, but I'm not sure.</p>
  
  <p>How should I debug and solve this issue?</p>
  
  <p><strong>EDIT</strong>: I also tried to pass a hash ref to the subroutine and do a dereferencing of the hash ref into another hash while doing all of the operations on the new hash.</p>