Jaime, 1. use strict (some of your errors derive from not using it). 2. When using a recursion, you need to have the following algorithm in mind: a. Stop when the breaking condition has been reached; b. Work on the problem on a small scale: solve the problem for the minimal atomic problem; c. Keep working on the bigger problem.
In your case, you don't have the breaking condition - meaning that even when you fix your code, you'll end up in an infinite loop. I've revised the code (to some extent), and I *think* the breaking condition should be something like the following: #------------------- code ----------------------# use strict; sub ShowValue { my $i = shift; my $v = shift; my $r = shift; $v =~ /\[(\d)\]/; # check the value of $v - the numeric last if $1 > 0; # get out when you over bound the threshold if (ref($r) eq 'ARRAY') { print "array\n"; for (my $x = 0; $x <= @$r; $x++) { &ShowValue($i + 4, $v."[$x]", @$r[$x]); # reference to array } } elsif (ref($r) eq 'HASH') { $v = $v. '->' if $v; foreach my $key (keys %$r) { &ShowValue($i + 4, $v.$key, %$r); # reference to hash } } else { print ' ' x $i, $v, ' : ', $r,"\n"; } } my %args; my @sequence; $args{'returnHash'} = {}; $args{'dest_x'} = 'x'; $args{'dest_y'} = 'y'; unshift @sequence, \%args; ShowValue (0,'',[EMAIL PROTECTED]); #------------------- end code ----------------------# In my case, it worked pretty fine, resulting in: array [0]->dest_x : dest_x [0]->returnHash : dest_x [0]->dest_y : dest_x HTH All the best, Schichmanter Eitan SDM Team Developer, Petah-Tikva, Israel Intel(r) [EMAIL PROTECTED] phone: +972-3-9207046 ------------------------------ Schichmanter Eitan, CM Consultant and Developer, LMB-Consulting LTD. [EMAIL PROTECTED] www.lmb.co.il >-----Original Message----- >From: [EMAIL PROTECTED] [mailto:perl-win32- >[EMAIL PROTECTED] On Behalf Of Jaime Teng >Sent: Wednesday, June 23, 2004 16:30 >To: [EMAIL PROTECTED] >Subject: need help printing data tree structure > >Hi, > >I am trying to write a routine that would print out the value(s) of >the entire variable either it be scalar, hash or array: > >######################################################## >sub ShowValue { > my $i = shift; > my $v = shift; > my $r = shift; > > if (ref($r) eq 'ARRAY') { > print "array\n"; > for (my $x = 0; $x <= @$r; $x++) { > ShowValue($i+4, $v."[$x]", $r[$x]); > } > } elsif (ref($r) eq 'HASH') { > $v = $v. '->' if $v; > foreach my $key (keys %$r) { > ShowValue($i+4, $v.$key, $r{$key}) > } > } else { > print ' ' x $i, $v, ' : ', $r,"\n"; > } >} > >my %args; >my @sequence; >$args{'returnHash'} = {}; >$args{'dest_x'} = 'x'; >$args{'dest_y'} = 'y'; >unshift @sequence, \%args; >ShowValue (0,'',[EMAIL PROTECTED]); >######################################################## > >I could not seem to get this working properly. Can anyone help? >Is there any perl functions/modules that do just this? > >thanks. >Jaime > > > >Email Advisory================================================== >To ensure delivery of message to [EMAIL PROTECTED], please contact your email >provider and ask them if your email server has a valid DNS entry. Public >Email Servers must have a valid hostname and routeable public IP Address >per RFC1912 compliance. > >To test the compliance of your email server, please send an email to: >[EMAIL PROTECTED]; our server will reply with a result within >minutes. >==================================================Email Advisory > >_______________________________________________ >Perl-Win32-Users mailing list >[EMAIL PROTECTED] >To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs