Are quotes around hash keys a good practice in Perl?

后端 未结 13 2062
伪装坚强ぢ
伪装坚强ぢ 2020-12-03 06:24

Is it a good idea to quote keys when using a hash in Perl?

I am working on an extremely large legacy Perl code base and trying to adopt a lot of the best practices s

13条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 07:14

    I don't think there's a best practice on this one. Personally I use them in hash keys like so:

    $ident{'name'} = standardize_name($name);
    

    but don't use them to the left of the arrow operator:

    $ident = {name => standardize_name($name)};
    

    Don't ask me why, it's just the way I do it :)

    I think the most important thing you can do is to always, always, always:

    use strict;
    use warnings; 
    

    That way the compiler will catch any semantic errors for you, leaving you less likely to mistype something, whichever way you decide to go.

    And the second most important thing is to be consistent.

提交回复
热议问题