in reply to General Solution: initializing multidimensional arrays
How would you do it?
Recursively.
#! perl -slw use strict; use Data::Dumper::SLC; sub multiDimInit { my( $value, $dim ) = ( shift, shift ); return $value unless $dim; return map{ [ multiDimInit( $value, @_ ) ] } 1 .. $dim; } my @multi = multiDimInit( 12345, 2, 2, 2, 2 ); Dump \@multi, 80, *STDOUT; __END__ P:\test>462436 [ [ [ [ [ '12345', ], [ '12345', ], ], [ [ '12345', ], [ '1234 +5', ], ], ], [ [ [ '12345', ], [ '12345', ], ], [ [ '12345', ], [ '1234 +5', ], ], ], ], [ [ [ [ '12345', ], [ '12345', ], ], [ [ '12345', ], [ '1234 +5', ], ], ], [ [ [ '12345', ], [ '12345', ], ], [ [ '12345', ], [ '1234 +5', ], ], ], ], ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: General Solution: initializing multidimensional arrays
by Roy Johnson (Monsignor) on Jun 01, 2005 at 14:19 UTC | |
by BrowserUk (Patriarch) on Jun 01, 2005 at 14:23 UTC | |
|
Re^2: General Solution: initializing multidimensional arrays
by dragonchild (Archbishop) on Jun 01, 2005 at 14:02 UTC |