Hi Monk
sub DeleteValueTreeWithinHash { my $HashData = $_[0]; my $FindValue = $_[1]; my $value = &RecursiveFunctionToDeleteValueWithinHash($HashData, +$FindValue); print Dumper ($value); %{$HashData} = undef; %{$HashData} = %{$value}; print Dumper ($HashData); }
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.
$VAR1 = { '' => undef };
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 = { '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 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.
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; }
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?
$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 ' => {} };

In reply to Problems With Hash Pointer Assignments by EchoAngel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.