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

前端 未结 9 1756
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:14

    Comment @shelfoo (reputation not high enough to add comment directly there yet!)

    Totally agree about Perl Best Practices by Damian Conway... its highly recommended reading.

    However please read PBP Module Recommendation Commentary which is a useful "errata" if you plan to use PBP for an in-house style guide.

提交回复
热议问题