Why do you need $ when accessing array and hash elements in Perl?

后端 未结 9 1913
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 16:22

Since arrays and hashes can only contain scalars in Perl, why do you have to use the $ to tell the interpreter that the value is a scalar when accessing array or hash elemen

9条回答
  •  半阙折子戏
    2020-12-11 16:41

    Slices aren't illegal:

    @slice = @myarray[1, 2, 5];
    @slice = @myhash{qw/foo bar baz/};
    

    And I suspect that's part of the reason why you need to specify if you want to get a single value out of the hash/array or not.

提交回复
热议问题