I have a problem accessing variables in a hash of hashes I don’t know what I have done wrong. While debugging the value of hash %list1 gives an undef, So I can’t get my values out .
use strict ;
use warnings ;
my $text = "The, big, fat, little, bastards";
my $Author = "Alex , Shuman ,Directory";
my %hashes = {1,2,3,40};
my %count = ();
my @lst = split(",",$text);
my $i = 0 ;
my @Authors = split(",", $Author);
foreach my $SingleAuthor(@Authors)
{
foreach my $dig (@lst)
{
$count{$SingleAuthor}{$dig}++;
}
}
counter(\%count);
sub counter
{
my $ref = shift;
my @SingleAuthors = keys %$ref;
my %list1;
foreach my $SingleAuthor1(@SingleAuthors)
{
%list1 = $ref->{$SingleAuthor1};
foreach my $dig1 (keys %list1)
{
print $ref->{$SingleAuthor1}->{$dig1};
}
}
}
In two places you are attempting to assign a hash reference to a hash, which results in this warning: Reference found where even-sized list expected.
Here are two edits you need:
See perlreftut for a useful and brief discussion of complex data structures.
For what it’s worth, your
counter()method could be simplified without loss of readability by dropping the intermediate variables.Or, as ysth points out, like this if you don’t need the keys: