EchoAngel has asked for the wisdom of the Perl Monks concerning the following question:
I have this function which is called by &DeleteValueTreeWithinHash(\%HashData, "index"); when I do a dumper on $value, i see all this data to screen. when I do a dumper on $HashData, i see no values.sub DeleteValueTreeWithinHash { my $HashData = $_[0]; my $FindValue = $_[1]; my $value = &RecursiveFunctionToDeleteValueWithinHash($HashData, +$FindValue); print Dumper ($value); %{$HashData} = undef; %{$HashData} = %{$value}; print Dumper ($HashData); }
Any ideas on what i'm doing wrong? All I wanted to do was create a recursive function and delete a branch or element if it finds the text there. Update: Maybe I didn't put enough details so here is everything. This below is how %HashData looks like before this function line &DeleteValueTreeWithinHash(\%HashData, "index");$VAR1 = { '' => undef };
This is my recursive function to remove the element. Note my hash structure above is multi dimensional such that it has no limit to it's depth.$VAR1 = { '0.29 type (ABC) {' => { '19.29 }' => {}, '18.28 ' => {}, '6.27 location(Y) {' => { '6.11 ' => {}, '7.12 + direction : out; ' => {}, '17.26 ' => {}, '18.27 + }' => {}, '8.13 + surface : 0.0; ' => {}, '10.25 + internal_power() {' => { + '16.24 ' => {}, + '11.17 related_outlet : "A"; ' => {}, + '12.23 rise_power(wind_template_7x +7) {' => { + + '14.21 index_2 ("4,5,6,7"); ' => {}, + + '13.20 index_1 ("1,2,3,4"); ' => {}, + + '15.22 hello : "kitty"; ' => {}, + + '12.19 ' => {}, + + '16.23 }' => {} + + }, + '10.16 ' => {}, + '17.25 }' => {} + }, '9.14 + function : "A"; ' => {} }, '2.8 location(A) {' => { '2.5 ' => {}, '4.7 + surface : 0.004189; ' => {}, '3.6 + direction : in; ' => {}, '5.8 } +' => {} }, '5.9 ' => {}, '1.3 area : 7.761600; ' => {}, '0.2 ' => {} }, '19.30 ' => {} };
This is the value of print Dumper ($value); I just want to set this as my main hash. Notice that any values with the word index is removed from the hash?sub RecursiveFunctionToDeleteValueWithinHash { my $HashData = $_[0]; my $FindValue = $_[1]; my $keys; foreach $keys (sort { $a <=> $b } keys %{$HashData}) { if ($keys =~ m/^(([\d]+)\.([\d]+) )/) { my $MarkerNumber = $1; my $line_data = $keys; $line_data =~ s/^([\d]+)\.([\d]+) //; if ($line_data =~ m/$FindValue/) { delete $$HashData{$keys}; next ; } my @values = (sort { $a <=> $b } keys %{$$HashData{$keys}}); if (scalar(@values) != 0) { $$HashData{$keys} = &RecursiveFunctionToDeleteValueWithinH +ash($$HashData{$keys}, $FindValue); } } } return $HashData; }
$VAR1 = { '0.29 type (ABC) {' => { '19.29 }' => {}, '18.28 ' => {}, '6.27 location(Y) {' => { '6.11 ' => {}, '7.12 + direction : out; ' => {}, '17.26 ' => {}, '18.27 + }' => {}, '8.13 + surface : 0.0; ' => {}, '10.25 + internal_power() {' => { + '16.24 ' => {}, + '11.17 related_outlet : "A"; ' => {}, + '12.23 rise_power(wind_template_7x +7) {' => { + + '15.22 hello : "kitty"; ' => {}, + + '12.19 ' => {}, + + '16.23 }' => {} + + }, + '10.16 ' => {}, + '17.25 }' => {} + }, '9.14 + function : "A"; ' => {} }, '2.8 location(A) {' => { '2.5 ' => {}, '4.7 + surface : 0.004189; ' => {}, '3.6 + direction : in; ' => {}, '5.8 } +' => {} }, '5.9 ' => {}, '1.3 area : 7.761600; ' => {}, '0.2 ' => {} }, '19.30 ' => {} };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problems With Hash Pointer Assignments
by gaal (Parson) on Nov 30, 2004 at 20:32 UTC | |
by EchoAngel (Pilgrim) on Nov 30, 2004 at 20:45 UTC | |
by gaal (Parson) on Nov 30, 2004 at 20:55 UTC | |
by EchoAngel (Pilgrim) on Nov 30, 2004 at 21:21 UTC | |
|
Re: Problems With Hash Pointer Assignments
by dragonchild (Archbishop) on Nov 30, 2004 at 20:21 UTC | |
|
Re: Problems With Hash Pointer Assignments
by osunderdog (Deacon) on Nov 30, 2004 at 20:14 UTC | |
|
Re: Problems With Hash Pointer Assignments
by revdiablo (Prior) on Nov 30, 2004 at 20:23 UTC | |
|
Re: Problems With Hash Pointer Assignments
by NetWallah (Canon) on Nov 30, 2004 at 20:25 UTC |