I think something like this is what you want,
That prints the data structure as:use Data::Dumper; my %kid; while (<DATA>) { chomp; my @line = split /,/; $kid{$line[1]}{$line[2]}{$line[3]} = { duration => $line[4], function_name => $line[5] }; } print Dumper(\%kid); __DATA__ 1,2,3,4,100,A 10,20,30,40,200,B 11,21,31,41,300,C 12,22,32,42,400,D 13,23,33,43,500,E 13,23,33,53,600,F 13,23,33,63,700,G 13,23,34,73,800,H 13,23,34,83,900,I 13,24,35,93,1000,J 13,24,36,103,1100,K
$VAR1 = {
'22' => {
'32' => {
'42' => {
'function_name' => 'D',
'duration' => '400'
}
}
},
'21' => {
'31' => {
'41' => {
'function_name' => 'C',
'duration' => '300'
}
}
},
'24' => {
'35' => {
'93' => {
'function_name' => 'J',
'duration' => '1000'
}
},
'36' => {
'103' => {
'function_name' => 'K',
'duration' => '1100'
}
}
},
'23' => {
'33' => {
'63' => {
'function_name' => 'G',
'duration' => '700'
},
'53' => {
'function_name' => 'F',
'duration' => '600'
},
'43' => {
'function_name' => 'E',
'duration' => '500'
}
},
'34' => {
'83' => {
'function_name' => 'I',
'duration' => '900'
},
'73' => {
'function_name' => 'H',
'duration' => '800'
}
}
},
'2' => {
'3' => {
'4' => {
'function_name' => 'A',
'duration' => '100'
}
}
},
'20' => {
'30' => {
'40' => {
'function_name' => 'B',
'duration' => '200'
}
}
}
};
Deep hashes like this are not the easiest thing to work with. Care must be taken to check existence of a key at each level while looking things up. From the feel of this sample problem, it's possible that Graph will make a more comfortable representation of the data.
After Compline,
Zaxo
In reply to Re: Hashes
by Zaxo
in thread Hashes
by flemi_p
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |