in reply to Re: Surprising Syntax
in thread Surprising Syntax

Another strange behaviour: If you write
use constant TEST => 'x'; my %h = (TEST => 1); print foreach keys %hash;
outputs: TEST and not 'x'

I think, one of the two behaviours is not ok. I just don't know which one :-)

Replies are listed 'Best First'.
Re: Surprising Syntax
by Abigail-II (Bishop) on Aug 13, 2002 at 12:45 UTC
    That's not surprising at all, because that's exactly what => is supposed to do: autoquote its left hand side if the left hand side is a simple unquoted string.

    TEST is a simple unquoted string, hence it gets quoted, and hence, it's not a constant.

    Compare:

    my %h = (time => 0); print keys %h;
    That also prints the string time, and not a number.

    You could always use +TEST or TEST(), as discussed in the manual page of constant.pm.

    Abigail

      I agree. The surprise was just in the context that a v-string is not autoquoted. So in my eyes, the behaviour with the v-string is not the same as with constants (and other subs) which makes me think that the v-string behaviour really is a bug.

      Best regards,
      perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

        The concensus on p5p seems to be that it's recognized as a bug. But to fix this (and some other v-string strangeness) isn't easy, as v-strings live on the point where the tokenizer, the parser and the magic system meet.

        It's where the dragons live.

        Abigail