另一个数据结构疑问。我会直截了当。这就是我所拥有的
use strict;
use warnings;
use Data::Dumper;
my $head= undef;
my $tail=\$head;
open FILE, "<datastored.txt" or die $!;
while (<FILE>){
my $node = {
"data" => $_ ,
"next" => undef
};
$$tail=$node;
$tail = \${$node->{"next"}};
};
# #1# Print full list #
print Dumper $head;
# #2# Delete the first node and display data of next node #
$head = $head->{next};
my $value = $head->{data};
这是我得到的输出
$VAR1 = {
'next' => \{
'next' => \{
'next' => \{
'next' => \undef,
'data' => 'line 4'
},
'data' => 'line 3
'
},
'data' => 'line 2
'
},
'data' => 'line 1
'
};
Not a HASH reference at linkedlist.pl line 32, <FILE> line 4. **<<<< My Problem and hence my question?**
注意 - 文件的内容datastored.txt
很简单
line 1
line 2
line 3
line 4
如果我看$head
最初的打印结果,它显然是一个散列中的散列等等,那么为什么删除第一个节点后数据结构的完整性受到阻碍?(请参阅输出最后一行的错误)