Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Question about returning array from sub

by QM (Parson)
on Jul 10, 2015 at 13:00 UTC ( [id://1134156]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Question about returning array from sub
in thread Question about returning array from sub

Perl does multidimensional arrays by storing elements of the sub-array in the parent array. So
$x[0][1] = 12;

is the syntactic-sugar equivalent of

$x[0]->[1] = 12;

(IIRC, in Perl 4, this was the required invocation.)

And the whole sub-array as

$x[0] = \@subarray;

You might also think about it like this:

@x = ( ["some", "sub", "array"], ["next", "sub", "array] );

which is making anonymous arrays, and assigning the lot to @x. And these can be nested as deeply as you have memory for (AFAIK, but that would be a good exercise to check).

Update:

Yes, it seems that simply nesting empty arrays keeps going until it runs out of memory, starts swapping, and in my case, is killed by the OS.

-QM
--
Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1134156]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found