in reply to Re: recursive hash layer removal question
in thread recursive hash layer removal question
I've not seen one of these before. It's an hash but it looks like an array ie '@'sub remove { my ($p, $d) = @_; if ($d-- > 1) { remove($_, ($d)) for values %$p; # Had second decrement here } else { my %newhash; for (values %$p) { @newhash{keys %$_} = values %$_; } $_[0] = \%newhash; } }
What is going on here then ? Checked out my cookbook etc but can't find a reference to this syntax. One other slight complication is the data can actually look like this;for (values %$p) { @newhash{keys %$_} = values %$_; } $_[0] = \%newhash;
Now when we collapse level 2 ie LCQT I don't want to change the value for 'W'. So only drop values on the target level if they are HASH. So really it's a mix of H,HOH and HOHOH etc. Thanks again for your help. Jeff$W={ 'A' => { 'L' => { 'D'=>99, 'X'=>99, }, 'C' =>{ 'E'=>99 }, }, 'X' => { 'Q'=>{ 'O'=>99, }, 'T'=>{ 'U'=>99, }, }, 'W' => 99, };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: recursive hash layer removal question
by Transient (Hermit) on May 11, 2005 at 14:24 UTC |