jpfarmer has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
I've been working on a recursive function, but I can't seem to make it return anything other than 0. The Dumper() statement in the exit case shows that I should be getting the correct value, but by the time it gets back to the main function, it's 0.
I'm assuming that I'm picking up another value from somewhere, but I have no idea from where. Any suggestions would be appreciated.
# Prototype defined to avoid 'function not defined' warnings # on compilation. sub unpack_row($@); sub unpack_row($@){ my $hash = shift(@_); my @row = @_; if(ref($hash) eq 'HASH'){ my $header = $hash->{'header'}; while(my ($key, $value) = each(%$hash)){ unpack_row($value, (@row, $key)); } } else { print Dumper((@row, $hash)); return (@row, $hash); } } my $hash = {}; $hash->{'foo'}->{'bar'}->{'bat'} = 5; print unpack_row($hash, ());
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive function always returns 0
by liverpole (Monsignor) on Feb 14, 2007 at 18:46 UTC | |
by jpfarmer (Pilgrim) on Feb 14, 2007 at 20:40 UTC | |
by liverpole (Monsignor) on Feb 14, 2007 at 21:27 UTC | |
by jpfarmer (Pilgrim) on Feb 14, 2007 at 18:51 UTC | |
|
Re: Recursive function always returns 0
by imp (Priest) on Feb 14, 2007 at 18:32 UTC | |
by jpfarmer (Pilgrim) on Feb 14, 2007 at 18:44 UTC |