Instead of

push @structure->[$i], $ex[$i];

You need

push @{ $structure->[$i] }, $ex[$i];

Which reads as; Use the $ith element of the array pointed at by the reference in the variable $structure as an array reference and then push the value of $ex[$i] onto that array.

The basic form is that in ?{ $ref }, that if $ref contains a reference to an aggregate datastructure (array or hash) then ?{ $ref }, where ? is either @ or %, allows you to use that data structure. (Hmm. That probably doesn't clarify anything!)

If $ref is an array ref, then @{ $ref } is the array it's referencing. Like wise for hashrefs and %{ $ref }.

There are shortcut versions of this syntax. If the reference is a simple scalar then you can omit the curlies: @$ref, but when the reference is itself a member of an aggregate, that doesn't work. I tend to use the full @{ $ref } syntax always. For both consistancy and because I don't have to remember when the shortcur does and doesn't work.

To get a better understanding of using references see perlreftut, perdsc and/or do a Super Search for "Tutorials references" here at PM.

Sorry for these naive questions.

Don't be. Leastwise, not for my sake. The only people who get upset about naive questions are those that either a) received their knowledge as a result of genetic imprinting; b) have forgotten that they once didn't know what they now know.

In either case, it's just intellectual snobbery--the very worst kind.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re^7: Best complex structure? by BrowserUk
in thread Best complex structure? 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.