in reply to Populating hash keys
Here is a recursive subroutine for that:
You might add some parameter checking if you need it and of course an iterative subroutine would be more efficient if you are into optimisation.sub applypath{ my($val, $index, @path) = @_; if(!defined($index)){ return $val; } return applypath($val->{$index}, @path); }
By the way I feel that my @keys = qw (1,2,3) is not exactly what you wanted to write as it is equivalent to my @keys = "1,2,3". Read about the qw operator on the perlop manpage (perldoc perlop).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Populating hash keys
by dda (Friar) on Oct 03, 2003 at 13:32 UTC |