in reply to Re^6: Best complex structure?
in thread Best complex structure?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Best complex structure?
by mat21 (Beadle) on Jun 10, 2005 at 09:21 UTC | |
by BrowserUk (Patriarch) on Jun 10, 2005 at 11:42 UTC | |
by mat21 (Beadle) on Jun 10, 2005 at 13:04 UTC | |
by BrowserUk (Patriarch) on Jun 10, 2005 at 14:08 UTC | |
|
Re^8: Best complex structure?
by planetscape (Chancellor) on Jul 03, 2005 at 11:22 UTC |