I've constructed a rather complex data structure, after reading in the perl book panther perl book I wanted to give it a shot (and using perl for 6 months )
I have a hash that used as a key a servername the value of the hash is a reference to an array that has 2 elements those are again 2 references to arrays the dump look like this,
the first one is a normal list the second one is again an array of arrays but I seem to have problems with my references.


I can traverse the code in a following mock up code.
<some make up code> while(($key, $value) = each(%hservers)) { $hserver{$keyX}->[0]->[1] ="some value"; $hserver{$keyX}->[1]->[0]->[0] ="1"; #secondpart $hserver{$keyX}->[1]->[0]->[1] =1; #secondpart $hserver{$keyX}->[1]->[0]->[2] ="parX"; #secondpart } </some make up code>
In this way I can build the structure completely the second part of the structure is build dynamically by my input/gui thingy :-).

Therefore the second part should be constructed by an init function.
My idea was to make a function and give the reference as argument.
And I need to be able to access the values later on too to add stuff , remove stuff from the structure by just passing the reference of the hash.

But in the init function I am not able to construct the code to traverse the hash and init it.
while(($key, $value) = each(%$href)) { %$href{$key}->[1]->[0]->[0] = 1; #this gives a syntax error %{$href{$key}}->[1]->[0]->[0] = "blah" #gives error print "$key\n"; # but when i do this the code prints all the keys o +f the reference to the hash. so I assume the the hash was passed thr +ough correctly }
Any pointers where I went wrong ?

dump of the hash

$VAR1 = 'server1'; $VAR2 = [ [ '', '4', '0', '0', '-1', '0', '', '0' ], [ [ 1, 1, 'par 2' ], [ 2, 999, 'par 1' ] ] ]; $VAR3 = 'server2'; $VAR4 = [ [ '', '2', '0', '0', '-1', '0', '', '0' ], [ [ 1, 1, 'par 2' ], [ 2, 999, 'par 1' ] ] ]; $VAR5 = 'server3'; $VAR6 = [ [ '', '3', '0', '0', '-1', '0', '', '0' ], [ [ 1, 1, 'par 2' ], [ 2, 999, 'par 1' ] ] ];

CODE and READMORE tags added by Arunbear


In reply to references troubles by Anonymous Monk

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.