In article <[EMAIL PROTECTED]>, Kevin Old
wrote:
> Hello everyone,
>
> I have a multidimensional array that I need to split into 4
> multidimensional arrays. I've tried the examples from the Programming
> Perl 3rd ed. Chapter 9 for splicing Arrays of Arrays and am not having
> any luck.
>
> Here's an example of how my data looks:
>
> [1 2 3 4 5 6 7 8 9 10 11 12]
> [A B C D E F G H I J K L]
>
> Here's how I need it to look:
>
> [1 2 3 4] [5 6 7 8]
> [A B C D] [E F G H]
>
> [9 10] [11 12]
> [I J] [K L]
Here's my version (I did need to peek at the Cookbook). I think this is what
you asked for...
my @AoA = (
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
['A'..'L'],
);
my (@AoA1, @AoA2, @AoA3, @AoA4);
for (0..$#AoA) {
# slice of AoA -- note position of {}s for AoA slice !!!!
push @AoA1, [ @{$AoA[$_]}[0..3] ];
push @AoA2, [ @{$AoA[$_]}[4..7] ];
push @AoA3, [ @{$AoA[$_]}[8..9] ];
push @AoA4, [ @{$AoA[$_]}[10..11] ];
}
# print Dumper([EMAIL PROTECTED]);
print "Array 1:\n";
foreach (@AoA1) {
print "@{$_}\n";
}
print "\n\n";
print "Array 2:\n";
foreach (@AoA2) {
print "@{$_}\n";
}
print "\n\n";
print "Array 3:\n";
foreach (@AoA3) {
print "@{$_}\n";
}
print "\n\n";
print "Array 4:\n";
foreach (@AoA4) {
print "@{$_}\n";
}
__END__
Output:
Array 1:
1 2 3 4
A B C D
Array 2:
5 6 7 8
E F G H
Array 3:
9 10
I J
Array 4:
11 12
K L
Am I close?
-K
--
Kevin Pfeiffer
International University Bremen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]