Perl 无法理解某些变量
我有一个代码行:Perl 无法理解某些变量,perl,Perl,我有一个代码行: $data->{nav}->{'current'}->{performance_gross} 我知道$data是标量,nav,performance\u gross是散列键。但是什么是'current'?nav,'current'和performance\u gross是分别计算字符串nav,current和performance\u gross的表达式。这三个字符串用作不同哈希的键 以下各项均相当: $data->{'nav'}->{'curr
$data->{nav}->{'current'}->{performance_gross}
我知道
$data
是标量,nav
,performance\u gross
是散列键。但是什么是'current'
?nav
,'current'
和performance\u gross
是分别计算字符串nav
,current
和performance\u gross
的表达式。这三个字符串用作不同哈希的键
以下各项均相当:
$data->{'nav'}->{'current'}->{'performance_gross'}
$data->{'nav'}{'current'}{'performance_gross'}
$data->{nav}->{current}->{performance_gross}
$data->{nav}{current}{performance_gross}
nav
、'current'
和performance\u gross
是分别计算字符串nav
、current
和performance\u gross
的表达式。这三个字符串用作不同哈希的键
以下各项均相当:
$data->{'nav'}->{'current'}->{'performance_gross'}
$data->{'nav'}{'current'}{'performance_gross'}
$data->{nav}->{current}->{performance_gross}
$data->{nav}{current}{performance_gross}
Perl允许在散列查找中对密钥使用任意表达式:
$hash{ arbitrary($code) . $here }
(结果字符串用作哈希键。)
但是,如果{
和}
之间只有一个简单的标识符,则会自动引用:
$hash{ some_word }
# is equivalent to
$hash{ 'some_word' }
这就是为什么在散列键中经常可以省略引号。但是显式地将字符串文本放在那里仍然有效,这意味着同样的事情。Perl允许在散列查找中对键使用任意表达式:
$hash{ arbitrary($code) . $here }
(结果字符串用作哈希键。)
但是,如果{
和}
之间只有一个简单的标识符,则会自动引用:
$hash{ some_word }
# is equivalent to
$hash{ 'some_word' }
这就是为什么在散列键中经常可以省略引号。但是显式地将字符串文本放在那里仍然是有效的,这意味着同样的事情。一个等价的访问将是
$data->{nav}{current}{performance\u gross}
一个等价的访问将是$data->{nav}{current}{performance\u gross}