in reply to Re^2: Two dimentional array
in thread Two dimentional array
Wow, looks good. I'm gonna experiment with it as soon as I get a chance. Thanks a lot.
:-) I wrote that short module just to show that multi-dimensional arrays can be done a la C, if you have nothing better to do. The only advantage is size - array elements occupy exactly four bytes (x86) which are packed into a pre-allocated string. There's no overhead introduced by individual elements or rows.
Of course Perl has a native array type. Multi-dimensional arrays are not a fundamental type but they're easily constructed with references. See perldata, perldsc.
The following code has serious side effects. Don't blindly cut and paste into your program (unless you like trouble).
#!/usr/bin/perl my @ary = map {["${_}1", "${_}2", "${_}3"]} 'a'..'u'; $\ = "\n"; $" = $, = ","; split ($,), print map {$ary[$_[$_]][$_]} 0..$#_ for glob join $,, map {"{@{[0..20]}}"} 1..3;
|
|---|