Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Do you know where your variables are?
 
PerlMonks  

Re: How do i create array of arrays

by Adam (Vicar)
on Jan 13, 2001 at 02:08 UTC ( [id://51547]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to How do i create array of arrays

my @array = ( 1..3 ); my $arrayRef = \@array; my @arrayOfArrays = ($arrayRef); print $arrayOfArrays[0]->[1];
I hope that helps.

{Editor note by davido: This approach is risky. For one thing, if @array ever changes, its changes will affect @arrayOfArrays. Thus, if you build up an array of arrays using this method inside of a loop, you could end up with multiple instances of the same @array, rather than multiple distinct and unique arrays as the contents of the @arrayOfArrays. Using my within the loop will create a new @array each time through, but better to be explicit about it rather than relying on lexical scoping which can confuse the reader later on.

Changing the second line to:

my @arrayRef = [@array];
will solve the potential problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://51547]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.