Hope I have my terms correct - I am looking for syntax to manipulate a slice of a hash_ref of a hash_ref.
What I want to do is replace the values "a" and "b" with "c" and "d" for KEY11 and KEY12, respectively. The code below is as close as I have come. The print Dumper results follow the code.

#!/usr/bin/perl -w use strict; $href->{KEY1}={KEY11=>"a",KEY12=>"b"}; print 'Initial condition for $href->{KEY1}={KEY11=>"a",KEY12=>"b"}'."\ +n"; print Dumper $href; ${$href->{KEY1}}{KEY11}="c"; print 'Change one key in the hash:${$href->{KEY1}}{KEY11}="c"'."\n"; print Dumper $href; @{$href->{KEY1}}{[qw/KEY11 KEY12/]}=("c" ,"d"); print 'Change all keys in the slice:@{$href->{KEY1}}{[qw/KEY11 KEY12/] +}=("c" ,"d")?'."\n"; print Dumper $href;
Results - Initial condition for $href->{KEY1}={KEY11=>"a",KEY12=>"b"} $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'KEY11' => 'a' } }; Change one key in the hash:${$href->{KEY1}}{KEY11}="c" $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'KEY11' => 'c' } }; Change all keys in the slice:@{$href->{KEY1}}{[qw/KEY11 KEY12/]}=("c" +,"d")? $VAR1 = { 'KEY1' => { 'KEY12' => 'b', 'ARRAY(0x50db350)' => 'c', 'KEY11' => 'c' } };

I end up with an anonymous array instead of the slice substitution I was looking for. Any help pointing out the correct syntax would be greatly appreciated.


In reply to HowTo Href_O_Href slice by sgrey

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.