in reply to using constants

The quotes are optional on barewords used as hash elements.
$hash{key} is the same as $hash{'key'}
$hash{shift} is the same as $hash{'shift'}
$hash{K} is the same as $hash{'K'}

Use
$hash{K()},
$hash{&K},
$hash{(K)} or
$hash{+K}
to work around the autoquoting.

Update: I thought I'd add a link to the relevant documentation, but I can't find documentation on this. perldata mentioned the auto-quoting property of =>, but not of the hash index.

Replies are listed 'Best First'.
Re^2: using constants
by Hena (Friar) on Oct 13, 2005 at 05:57 UTC
    Ah, Thanks. I Should have realised that :). Btw. Whats that + do? I understand the braces and &.

      This question is in the docs. Specifically, perlop.

      Unary-+ does nothing, but where XXX is a bareword, +XXX and (XXX) are expressions. Only barewords are auto-quoted, not expressions.