Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

general solution Re: Re: Re: Re: dimensioning arrays

by andye (Curate)
on Feb 17, 2001 at 01:18 UTC ( [id://58987]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: dimensioning arrays
in thread dimensioning arrays

This is a solution. Not very efficient though (sorry)... but I found it interesting.

sub ar_init { my $shift = shift ; (defined $_[0]) ? [ map { ar_init(@_) } (1..$shift) ] : $shift ; } my $array_ref = ar_init(3, 2, 4, 'pop '); print $array_ref->[2][0][3]

Since lists are 'flattened' in subroutine calls, you could put the dimensions in an array @dim = (3, 2, 4) and call it using ar_init(@dim, 'foo') - it would have the same effect. Note that the whole thing is constructed using references - you'll need to understand references for whatever solution you use. I like the explanation of reference syntax in _Effective_Perl_Programming_.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 15:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found