in reply to Re: Building hash tree from data file -contd
in thread Building hash tree from data file -contd
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
|
|---|