How come 'Value2' is changed to 'Value_two', but 'key2' is unchanged?
Because the keys aren't dealt out into $_ in the same way as the values. Consider:
qwurx [shmem] 15:35 ~ > perl -MDevel::Peek -e '%hash = qw(a 1 b 2 c 3) +; for(%hash){print STDERR "$_: ";Dump $_; s/b/d/;} print "$_ => $hash +{$_}\n" for sort keys %hash' c: SV = PVIV(0x8168b10) at 0x8166b44 REFCNT = 2 FLAGS = (POK,FAKE,READONLY,pPOK) IV = -289776295 PV = 0x8187928 "c" CUR = 1 LEN = 0 3: SV = PV(0x8167ae8) at 0x8167894 REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x818f380 "3"\0 CUR = 1 LEN = 4 a: SV = PVIV(0x8168b20) at 0x8166cf4 REFCNT = 2 FLAGS = (POK,FAKE,READONLY,pPOK) IV = -902917054 PV = 0x817be80 "a" CUR = 1 LEN = 0 1: SV = PV(0x8167b00) at 0x8166c28 REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x817ecb0 "1"\0 CUR = 1 LEN = 4 b: SV = PVIV(0x8168b50) at 0x818dfd8 REFCNT = 2 FLAGS = (POK,FAKE,READONLY,pPOK) IV = 14385563 PV = 0x81876b0 "b" CUR = 1 LEN = 0 2: SV = PV(0x8167ba8) at 0x8166d90 REFCNT = 2 FLAGS = (POK,pPOK) PV = 0x81866b0 "2"\0 CUR = 1 LEN = 4 a => 1 b => 2 c => 3

The flags for a hash key are (POK,FAKE,READONLY,pPOK), for values they are (POK,pPOK). Which means you manipulate the actual content modifying a value, but you're operating on fake variables modifying the keys.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re^4: Modifying the keys in a hash by shmem
in thread Modifying the keys in a hash by Mandrake

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.