hi,

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:

use 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
but the question is

What do you want to achieve using the data structure?

cheers , baxy

In reply to Re: Generating recursive hash by baxy77bax
in thread Generating recursive hash by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.