So I just started using Perl, and I had to write a database for a website. I still don't know a lot about Perl, but with what I knew the best way to do it was with a bunch of hashes. That way I had links, and the categories of links all organized neatly. I accomplished this by creating pointers which pointer to other pointers and so on until they pointed to hashes ( a sort of hash of hashes of hashes etc.)

I am tired of manually updating this database and have endeavored into writing an editing perl script. I am stuck on how to edit the actual data structure. Here is a general idea of how it looks like and my problem
$A = { B => { 1 => bla, 2 => bla, 3 => bla }, C => null, D => { 52 => bla, 53 => bla } }


My problem is encountered when I try to change "C" and make it point to not a value but a hash or list. I know have to reinitialize C => {} then $A->{$C}->{$23} = bla. To do my add method, I take in two parameters, the location which is $a->{$c} and the key,data set ($23, bla.) I want to make this dynamic so if $a originally points to null, I want to be able to take the location that was passed in, $a->{$c}, and try to make that key data set, if I can't make it check if $c points to a hash or value, if it doesn't exist, go back to $a and see if that points to a hash and if it doesn't make it point to a hash, then i will be able to add the desired data.

I have the idea in my head, I just can't figure out a way to go backwards through the references (ie given a final location break that location up and go from the front, or take the final location apart part by part from the back)

I am about to resort to passing in the location as a string, breaking up the string, and getting breaking it up that way. Sorry if this is confusing I tried to simplify it out because at this point my data structure is pretty ... pointee.

In reply to Going Backwards In Reference by Spiffy

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.