gpt4 book ai didi

perl - 标量在perl中是什么意思?

转载 作者:行者123 更新时间:2023-12-03 22:59:13 25 4
gpt4 key购买 nike

在 perl 中,您有三个主要的 data types 、“标量、标量数组和标量关联数组”。 perl 到底想用“标量”这个名字表达什么?什么是隐喻,应该形成的心理形象?
我可以推断出一个类比:单个值、一个值列表、一个命名值列表。但这并不能帮助我理解为什么使用“标量”这个词。 Perl 的标量肯定不是 resemble a ladder .

最佳答案

这个概念在 Variable (Computer Science) 中有原则性的描述。其中它说:

In computer programming, a variable or scalar is a storage location(identified by a memory address) paired with an associated symbolicname, which contains some known or unknown quantity of informationreferred to as a value. The variable name is the usual way toreference the stored value, in addition to referring to the variableitself, depending on the context.


在 Perl 中,标量变量保存单个值。虽然 Perl 标量通常与符号名称相关联,但并非必须如此;您可以拥有一个仅由标量引用引用且不与符号配对的标量。 “标量”一词在计算机编程中的使用可能源自数学中的类似用法,如 Scalar (Mathematics) 中所述。 :

A scalar is an element of a field which is used to define a vectorspace. A quantity described by multiple scalars, such as having bothdirection and magnitude, is called a vector.


应用于 Perl 时,标量在 perldoc perldata 中进行了描述。 :

A scalar may contain one single value in any of three differentflavors: a number, a string, or a reference. In general, conversionfrom one form to another is transparent. Although a scalar may notdirectly hold multiple values, it may contain a reference to an arrayor hash which in turn contains multiple values.


Perl 标量在内部存储一些东西;一个 IV(整数值)、一个 NV(浮点数值)、PV(指向字符串值的指针)、SV(一个引用)、一个引用计数、一些用于跟踪标量是否具有 Unicode 语义的各种标志,其他”魔术”,以及正在使用的各种存储类型中的哪一种。在任何给定时间,并非所有这些存储桶都在使用中,填充哪些存储桶取决于标量的定义方式和使用方式(包含字符串的标量稍后可能会在内部填充 IV 或 NV 字段,如果它被视为数字)。这在 perlguts 中有描述,但您通常无需担心。
您可以非正式地将标量视为单个存储单元,其中可能包含数字、字符串或引用。您可以将标量视为独立变量、标量引用所引用的存储单元,或者数组或散列的单个元素。

关于perl - 标量在perl中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67292717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com