in reply to Use of the => operator

You need to quote them explicitly so they are never tested as numbers. The fat comma stringification comes after numeric interpretation and before keyword recognition. I believe the details should be in toke.c in the root of the perl source distrubution.

(Added) Another few examples,

$ perl -Mstrict -we'BEGIN {$_="foo";} sub bar () {"quux"} my %foo = ( +1e0 => "foo", bar => "quux", length => "baz");print "@{[keys %foo]}", + $/' length bar 1 $
That shows numeric interpretation, then fat comma stringification, then keywords and subs. If keywords had been interpreted, the "length" key would have been "3" instead. If constant subs had been interpolated before, "bar" key would have been "quux".

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Use of the => operator
by traveler (Parson) on Aug 09, 2004 at 21:39 UTC
    Am I correct in assuming the reason for doing the numeric interpretation first is to be able to say  my %foo = ( 3+5 => "something");? Presumably if fat comma stringification came first, this would become a parse error.

      That comes from the high precedence of '+' over '=>'.

      If stringification came first there would be no error; you'd wind up with the string '3+5' as a key, which is perfectly all right. Fat comma stringifies like qw, breaking on whitespace.

      $ perl -e'%foo = ("3+5", "something");print keys(%foo),$/' 3+5 $

      After Compline,
      Zaxo

        Doh! I talked myself out of believing that, somehow.

        Now, of course, the question is which way is better... I guess that could be a Meditation some day.

      I don't see why you need to look for reasons for stringification to apply to things that are already valid constants. v-strings introduced a new class of these, and %foo = (v48 => "zero?"); suddenly changed meaning, so that a key of "0" was used instead of a key of "v48". This was "fixed" in 5.8.1 to restore the "v48"-behavior for backward compatilibity, but the 5.6-5.8.0 way (where v48 is "0") was actually more consistent.