in reply to Re: quick question about hash element access
in thread quick question about hash element access
Only with error checking, of course. Substitute while ... with foreach (split(/\./, $path) (and $1 with $_) for slightly different flavor.sub hpath(\%$) { my ($href, $path) = @_; while ($path =~ /\G(.+?)\.?/gc) { $href = $href->{$1}; } return $href; } my %c = (1 => { 2 => { 3 => 4 }}); print hpath(%c, "1.2.3");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: quick question about hash element access
by argggh (Monk) on Jun 28, 2003 at 15:27 UTC |