well, GrandFather has a point! An alternative to what you are asking is to create a tree structure and then walk through it (it is more memory efficient then building hash of hashes). something like this:
but the question isuse strict; my %hash; while (<DATA>){ chomp; my @array = split(',',$_); my ($child, $parent) = ($2,$1); $hash{$array[1]} = [] unless (exists $hash{$array[1]}); push @{$hash{$array[1]}}, $array[0]; } #and now you do the Johnny Cash (walk the line) my @line; _Johnny(5); # entry that you wish to query foreach (@line){ print $_ . ","; } #------------------------------------------------# sub _Johnny { my $x = shift; push (@line,$x); for (@{$hash{$x}}){ _Johnny($_); } } #------------------------------------------------# __DATA__ 3,1 5,1 4,3 2,7 6,4 8,2 7,6 11,5 12,5 43,11 15,11
What do you want to achieve using the data structure?
cheers , baxyIn reply to Re: Generating recursive hash
by baxy77bax
in thread Generating recursive hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |