Perl 的标志与内存分配有什么关系吗?
可能的重复:
为什么 Perl 变量需要以 $、%、@ 开头?
如果没有这个或类似的东西,其他脚本语言似乎也能相处得很好。
我想这与内存分配和帮助解释器加快速度有关,但我找不到任何具体的信息。 $scalar 可能会放入堆栈,@array 放入堆,%hash ?也进入堆吗?那么?子程序呢?
有人可以帮我解决这个问题或向我指出一些文档吗?我仍在努力掌握一些基础知识并了解一切在幕后如何运作......
Possible Duplicate:
Why do Perl variables need to start with $, %,@?
Other scripting languages seems to get along just fine without this or something similiar.
I guess it has something to do with memory allocation and helping the interpreter in order to speed things up, but I couldn't find anything specific on it. $scalar would probably be put into stack, @array into heap and %hash? Into heap as well? And what about ?subroutine?
Could someone help me figure this out or point me to some documentation? I am still trying to grasp some fundamentals and understand how everything works under the hood...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为它更容易阅读。
通过符号,您可以知道哪些标识符是名词,以及它们是单数还是复数。这与英语中我们有单数和复数限定词和一致的原因相同,例如thisspeciesis与thesespeciesare。很高兴知道哪个是哪个。
Because it makes it easier to read.
You know which identifiers are nouns, and whether they're singular or plural, because of the sigaldry. It's the same reason in English we have singular and plural determiners and agreement, as in this species is vs these species are. It's nice to know which is which.
Perl 将与名称相关的所有数据存储在单个符号表条目中。存储在那里的结构称为typeglob。
$foo
、@foo
、%foo
和&foo
(子例程引用)的值都是存储在“foo”的 typeglob 中。整个 typeglob 表示为*foo
(其中*
表示“所有符号”)。所有这些都在 Perl 文档的 perldata 部分中进行了解释。Perl stores all data associated with a name in a single symbol table entry. The structure stored there is called a typeglob. The values for
$foo
,@foo
,%foo
, and&foo
(subroutine reference) are all stored in the typeglob for "foo". The entire typeglob is denoted*foo
(where*
indicates "all sigils"). All this is explained in the perldata section of the Perl documentation.