N00bie Alert

I was trying to do what I thought was a simple conditional assignment using the  ?: operator on a hash value. The code follows

%HashTemplate =( several key value pairs );
%WorkingCopy = ();
$key = 0;
%WorkingCopy = %HashTemplate;
 for $key (keys $WorkingCopy) {
  $WorkingCopy{$Key} = /p1/ ? "this" : "that";
 }

what I expected was that whenever $WorkingCopy{$key}= /p1/was true (i.e., matched the value), "this" would be assigned to $WorkingCopy{$key}; if false (match failed) "that" would be assigned to $WorkingCopy{$key}

I even tried the alternative:
$WorkingCopy{$Key} = /p1/ ? $WorkingCopy{$key} = "this" : $WorkingCopy{$key} = "that";

In all cases the match fails as written, resulting in: ($WorkingCopy{$key} = "that" for all elements in the hash. Even with different permutations of p1 --e.g, quoted or not quoted within forward slashes, the match fails. (I know p1 exists as hash value).

I've read through the pertinent parts of Camel several times (followed their example), but I'm obviously still missing something basic in my understanding of ?: in a pattern matching expression as above. any light you can shed on my (mis)understanding of the ?: and my example, is most appreciated.

thanks in advance

In reply to ?: conditionals by lcschreier

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.