Thanks for the responses

I was also trying to use the recursive functions to read and print from the data file.

The code doesn't have the logic to build the tree but I was trying to get the sequence correctly.

Looking at your scripts, I think I should scrap this and look to build on what you provided.

Below is the code:-

my @arr = ( 'NA', 'EU' ); my $base = 'Countries'; process_full_list( $base, @arr ); sub process_full_list { my ($base1, @arr1 ) = @_; my $elem; print "############################\n"; print "In process full list: $base1 : @arr1\n"; print "############################\n"; foreach $elem ( @arr1 ) { process_next( $base1, $elem); } } sub process_next { my ( $r_base, $r_elem ) = @_; my ( $new_base, $new_elem, @new_arr); print "\tIn process next: $r_base : $r_elem\n"; # The if loop is temporary. It will be replaced by a # sub that will fetch the next array to process by # reading from the file based on the search string. if ( $r_elem eq 'NA' ) { @new_arr = ( 'US', 'CA' ); } elsif ( $r_elem eq 'EU') { @new_arr = ( 'FR', 'IT' ); } elsif ( $r_elem eq 'US') { @new_arr = ( 'NY', 'LA' ); } elsif ( $r_elem eq 'CA') { @new_arr = ( 'TO', 'VC' ); } if( defined ( $r_elem ) && (@new_arr) ) { print "\tnew_base = $r_elem: new_arr=@new_arr\n"; process_full_list( $r_elem, @new_arr ); } }

The output for the above is

########################################### In process full list: Countries : NA EU ########################################### In process next: Countries : NA new_base = NA: new_arr=US CA ########################################### In process full list: NA : US CA ########################################### In process next: NA : US new_base = US: new_arr=NY LA ########################################### In process full list: US : NY LA ########################################### In process next: US : NY In process next: US : LA In process next: NA : CA new_base = CA: new_arr=TO VC ########################################### In process full list: CA : TO VC ########################################### In process next: CA : TO In process next: CA : VC In process next: Countries : EU new_base = EU: new_arr=FR IT ########################################### In process full list: EU : FR IT ########################################### In process next: EU : FR In process next: EU : IT

In reply to Re^2: Building hash tree from data file -contd by Anonymous Monk
in thread Building hash tree from data file -contd 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.