As the others have mentioned, what you're tripping over is a DWIM (Do What I Mean) feature of Perl: under certain circumstances, some words are assumed to have quotes around them when used on the left of the double arrow (or "fat comma") and in hash lookup curlies. (Did I miss any cases? There's also special rules for package names, but they're a bit different.) You can tell Perl's parser that you really didn't mean a string there by adding the correct incantation:
#!/usr/local/bin/perl -wl use strict; use constant TESTVALUE => 1; my %hash1 = (TESTVALUE() => "OK"); my %hash2 = (123 => TESTVALUE); my $hashValue; print $hash1{1}; print $hash1{+TESTVALUE}; print $hash1{$hash2{123}};
As you see, you do not have to use the comma instead of the double arrow - as long as Perl knows you mean the left side to be an expression, not a string. The same is true for hash lookup curlies. Note that prepending a plus sign won't work for the fat comma, though appending parens will work for the hash lookup. It's a bit confusing at first to remember which rules apply where, but you'll get used to them quick. In practice I find the specific rules and exceptions chosen to be the most convenient ones.

Makeshifts last the longest.


In reply to Re: Hash values and constants by Aristotle
in thread Hash values and constants by Marcello

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.