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

后端 未结 6 1898
陌清茗
陌清茗 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:16

    This is because Perl uses sigils:

    In computer programming, a sigil (pronounced /'sɪdʒ.ɪl/ or /'sɪg.ɪl/; plural sigilia or sigils) is a symbol attached to a variable name, showing the variable's datatype or scope. The term was first applied to Perl usage by Philip Gwyn in 1999 to replace the more cumbersome "funny character in front of a variable name". The name is based on the word meaning a magical symbol (see sigil (magic)).

提交回复
热议问题