All, I'm dealing with data in an "infinate dimension hash", that is, a hash where the number of keys to fetch a value is unknown and is not of an arbitary size. For example I could have:
$DATA{1}{a}{e} = 'snu'; $DATA{2}{a}{f} = 'woo'; $DATA{3}{b} = 'foo'; $DATA{4}{a}{e} = 'bar'; $DATA{5}{d} = 'bop';
I'm writing some functions to work with the data and reading the hash and just particular branches of keys has not been a problem. But I'd like to be able to arbitarily create a branch in this data structure based on a reference to a point in it. So for example, I'd like to be able to do:
put_element($DATA{3}, 'h', 'i', 'worked');
Which would in effect create the following:
$DATA{3}{h}{i} = 'worked';
This function would be useful in culling and replacing brances of the data structure, and so on. But, alas, I am having issues. After I call the function that I have written, and then walk the subsiquent hash, it only contains the original seeded values, and not the one I added with my function. I can't figure out what is wrong, or more importantly, how to make it do what I would like. The function, as I have written it, is as follows:
sub put_element { my $current = shift || die("Need root hash reference for put_element +!"); # reference to the current level my $value = pop || die("Need value to be put for put_element!"); + # value to be placed in structure $current = $$current{shift(@_)} while (@_ > 0); ${$current} = $value; return 1; }
Any input into where my errors may be is appreciated.

Thanks,
Scott


In reply to Missing something with regards to references by scottb

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.