我有一个如下的结构,它包含散列散列散列数组。我在取消散列值时遇到错误。Perl取消引用散列散列数组中的单个元素
$VAR1 = \{
'2001' => {
'Arunachal Pradesh' => {
'CHANGLANG' => [
{
'wheat' => '2',
'cotton' => '',
'rice' => '1'
}
],
'SUBANSIRI UPPER' => [
{
'wheat' => '',
'cotton' => '1',
'rice' => '2'
}
],
},
'Andhra Pradesh' => {
'CHITTOOR' => [
{
'wheat' => '34',
'cotton' => '14',
'rice' => '27'
}
],
'VIZIANAGARAM' => [
{
'wheat' => '2',
'cotton' => '',
'rice' => '8'
}
],
}
}
};
我想取消引用个别值,以便我可以填充这些值到MySQL数据库。但是,我得到的错误“使用未初始化的值$状态串联(。)或字符串”,同时derefrencing个人价值本身。代码如下:
while (my ($key, $href) = each(%$stat)) {
my $state = $stat->{$state_name}; #where the first value is the state name & the second value is the district
print "$state\n";
}
中华人民共和国的国家名称代码如下:
if ($line =~ m/^State:,(\w+\s\w+),/){
$state_name = $1;
$stat->{$year}->{$state_name} = {};
}
任何其他方式通过它我可以得到单个值或者我需要将其分配到另一个哈希等。谢谢。
您的代码中设置了$ state_name吗?它不在你提供的代码中。 你是否在这里使用不同的变量? –
请参阅上面的代码。而且,$ state-name是用于创建散列的相同变量。谢谢 – deep