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

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

    http://www.wall.org/~larry/natural.html:

    English uses number and word order, with vestiges of a case system in the pronouns: "The man looked at the men, and they looked back at him." It's perfectly clear in that sentence who is doing what to whom. Similarly, Perl has number markers on its nouns; that is, $dog is one pooch, and @dog is (potentially) many. So $ and @ are a little like "this" and "these" in English.

提交回复
热议问题