Note: my %page = %{ ... }; is making a copy of the hash. Changes will not be retained.
Are you sure? Try running this:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash = (key1 => { subkey1 => [ qw(a number of elements in an array) + ], }, key2 => "value2"); my %hash2 = %hash; $hash2{key1}->{subkey1} = [ qw(other elements in an array) ]; print Dumper(\%hash); print Dumper(\%hash2);
A hash copy will only do a shallow copy, i.e. the references are copied instead of the contents of those references. That's why changes to %hash2 also end up in %hash. Using Devel::Peek to display %hash and %hash2 will make this even more clear. Search for the lines looking like:

Elt "key2" HASH = 0x3e4d4a SV = PV(0x80f6498) at 0x81009c4

and note the addresses.

Arjen


In reply to Re: Re: Getting a branch of a nested hash by Aragorn
in thread Getting a branch of a nested hash by legLess

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.