Is there any way to use a “constant” as hash key in Perl?

前端 未结 9 1720
Happy的楠姐
Happy的楠姐 2021-02-03 20:39

Is there any way to use a constant as a hash key?

For example:

use constant X => 1;

my %x = (X => \'X\');

The above code will cr

9条回答
  •  有刺的猬
    2021-02-03 21:16

    => operator interprets its left side as a "string", the way qw() does.

    Try using

    my %x = ( X, 'X');
    

提交回复
热议问题