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, ());
In reply to Recursive function always returns 0 by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |