in reply to Problems with HOHOH modification

How should I do for example add a "Alphakey2" that is a key to "Betakey2". Where "Betakey2" Has no gammakeys?
$HOHOH{ Betakey2 }{ Alphakey2 } = undef;

I strongly suspect that you mean something different to what you asked for, but the above is what you asked for.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Problems with HOHOH modification
by Anonymous Monk on Feb 13, 2008 at 18:47 UTC
    Sorry that my previous explenation was not strict enough. Undef is not thing I need becouse it would undefine values that have allredy have been defined. I would for example like to create the following structure, by adding keys "Alphakey2" and "Betakey2".
    Alphakey1 { =>Betakey1 { Ļ { =>Gammakey1=1 =>Gammakey1=2 } } } Alphakey2 { =>Betakey2 { } }
    If "Alphakey2" and "Betakey2" are not allready defined. If there allredy are keys named "Alphakey2" and "Betakey2" there should be no changes.

      $HOHOH{'Alphakey2'}->{'Betakey2'} ||= {}; will initialize with a new (empty) hashref if there's not already an existing key at that level (although keep in mind that that will also populate $HOHOH{'Alphakey2'} with a new hashref as well if it doesn't exist; search for "autovivification" for more details, and go read perlreftut and perlref as well until it becomes clear).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        $HOHOH{'Alphakey2'}->{'Betakey2'} ||= {}; This was the syntax I was looking for. I havenīt seen this type of syntax before. Thank You. Is it possible to use in on something else? If var is not assigned to assign two to it.. $var||=2;

      You want $HOHOH{ Betakey2 }{ Alphakey2 } to contain an empty hash? Then assign it an empty hash:

      $HOHOH{ Betakey2 }{ Alphakey2 } = {};

      But again, I suspect that you are not describing your requirements very well? For example, what happened to the top level hash in youe examples? What you have posted looks like two entirely different data structures.

      I'm not trying to offend you, but whilst your requirement may be entirely obvious to you, it is far from clear to us reading your post.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.