我有以下代码,其中我有一个结构($node),它是声明的标量,但似乎是使用的散列:
sub LoadData()
{
#not significant code here
my $node = {
BaseName => "deviceA",
SysDescr => "Example device",
SysObjectId => "SysObjectIdTest",
ManagementIpAddress => "BLABLABLA",
Protocol => "1",
};
$store->AddDeviceData( 1, $node->{BaseName}, $node );
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:正如我们在上面看到的那样声明的$node是散列还是标量?我的意思是,两者之间有区别吗(就行为而言)
my $hash = {
#some foo => "bar" assign here
};
Run Code Online (Sandbox Code Playgroud)
和
my %hash = (
#some foo => "bar" assign here
);
Run Code Online (Sandbox Code Playgroud)
和
my %hash = {
#some foo => "bar" assign here
}
Run Code Online (Sandbox Code Playgroud)
PS:它表现为散列引用,因为 AddDeviceData() 将最后一个参数限制为散列引用。
PSS:也许它与上下文有关;分配给标量的散列意味着分配对散列的引用而不是散列本身的内容,但我不太确定。