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

后端 未结 9 1920
爱一瞬间的悲伤
爱一瞬间的悲伤 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:45

    The sigil provides the context for the access:

    • $ means scalar context (a scalar variable or a single element of a hash or an array)
    • @ means list context (a whole array or a slice of a hash or an array)
    • % is an entire hash

提交回复
热议问题