Alright, just an update. I believe I have found the problem.
use strict;
use Data::Dumper;
my $start = {};
sub add{
my $root = shift;
my $level = shift;
my @items = @_;
if(!@items) {return $level-1;}
#print "level = $level\n";
while(@items) {
my $first = shift @items;
$root->{$first}->{count}++;
if(!exists($root->{$first}->{children})) {$root->{$first}->{ch
+ildren}={};}
#print "\t" x $level . "first = " . $first . ", values = " . j
+oin(',',@items)."\n";
$root->{$first}->{max} = add($root->{$first}->{children}, $lev
+el+1, @items);
}
}
add($start, 1, 1..4);
add($start, 1, 1..2);
print Dumper($start);
I was passing hash reference that were undefined, which is not a good thing apparently. So, I fixed that problem.