nujersedvl has asked for the wisdom of the Perl Monks concerning the following question:

i need an array of arrays, but instead of using: @array=(['1', '2'], ['1', '2']); i need it to go something like this: @array=(@otherarray, ['1', '2']); except it doesn't work with this syntax. how do i do this? - thanks

Replies are listed 'Best First'.
(zdog) RE: array of arrays
by zdog (Priest) on Jul 29, 2000 at 23:37 UTC
    You may want to look here to find the answer to your dilema.

    Good luck.

    Zenon Zabinski | zdog | zdog7@hotmail.com

Re: array of arrays
by jcouto (Novice) on Feb 14, 2000 at 15:15 UTC

    The content of an array element has to be a reference
    For example: $array[0]=\@otherarray
    stores a reference to @otherarray into the first element
    of @array.

    In the second question, what you do first: @array=({hashkey => [@otherarray, @etc]})
    stores into @array a reference to an anonymous
    hash with just one key, hashkey, and a value, a reference
    to an anonymous array (the joining of @otherarray and
    @etc) and, again, the second line should use a reference: $array[0]{hashkey}[0]=\@otherarray;
    perldoc perlref has a good tutorial on references; you
    need to master them to do complex datastructures in Perl

RE: array of arrays
by h0mee (Acolyte) on Feb 15, 2000 at 00:32 UTC
    Easy:
    @list = qw(this that and another); @array = ([@list], [1, 2, 3]); #value of $array[0][2] is now 'that'
    You can then reference the internal arrays as you would any multidimensional array.
    The thing to keep in mind here is that hashes and arrays can only keep scalar values- so referencing
    @array
    is doing it in list mode.
    [@array] \@array
    is fetching it as a reference. Keep in mind that that \@array is only a shallow copy- modifying the value in a dereferenced context will modify @array itself, where as modifying the value of [@array] will keep @array untouched.
Re: array of arrays
by Anonymous Monk on Feb 14, 2000 at 00:57 UTC
    let me explain more. what i need is like this:
    @array=({hashkey => [@otherarray, @etc]}); $array[0]{hashkey}[0]=@otherarray - this doesn't work either
    What i'm doing is sort of like a linked list, except it can point to many different elements which are all arrays. I need to extract the different values and then do some stuff with those arrays.
Re: array of arrays
by Anonymous Monk on Feb 14, 2000 at 00:38 UTC
    You might try assigning members individually. For instance: $array[0] = @otherarray; $array1 = '1', '2';