Why do Perl variables need to start with $, %,@ (sigils)?

后端 未结 6 1876
陌清茗
陌清茗 2020-12-05 00:47

Why do Perl variables need to start with different characters (sigils)?

  • Scalar variables start with $

  • Hashes start with %

6条回答
  •  自闭症患者
    2020-12-05 01:10

    When I started out using Perl it was explained to me that these characters were chosen because:

    • $ looked a bit like an 's' so that was for scalars,
    • @ has an 'a' in the middle so that was for arrays, and
    • % was for hashes because it looked like a key-value pair divided by a slash.

提交回复
热议问题