Subject: bug#66178: 30.0.50; cperl-mode inconsistent hash key fontification

From: Harald Jörg <[email-masked]>
Date: Sun, 24 Sep 2023 13:44:02 +0000

tags 66178 + wontfix
thanks

Mauro Aranda <[email-masked]> writes:

> emacs -Q
> C-x C-f bug.pl
> M-x cperl-mode
> my %factorial = (
>          0 => 1,
>          zero => 1
>         );
>
> zero is recognized as a string, 0 is not.

This might look surprising, but it is intentional.

zero is a bareword which undergoes hash-key stringification.

The digit 0, on the other hand, is converted to a string according to
Perl's type conversion rules.  That is a different thing: Perl's type
conversion converts all of 0, 000, 0.0, 0E0 to the hash key "0".

Let me expand your example to demonstrate some more cases where the hash
key is (correctly) not fontified as a string:

my %hash = (
    "0"    => 'The string "0"',
    "00"   => 'The string "00"',
    0      => 'A number which is converted to the string "0"',
    00     => 'A number which is converted to the string "0"',
    0.0    => 'A number which is converted to the string "0"',
    0E0    => 'A number which is converted to the string "0"',
    zero   => "A bareword which is stringified",
    zero() => "The function's return value is the key",
    +zero  => "The function's return value is the key",
);

-- 
Cheers,
haj