I have an array, @array
, of array references. If I use the range operator to print elements 1 through 3 of @array
, print @array[1..3]
, perl prints the array references for elements 1 through 3.
Why when I try to dereference the array references indexed between 1 and 3, @{@array[1..3]}
, perl only dereferences and prints out the last element indexed in the range operator?
Is there a way to use the range operator while dereferencing an array?
Example Code
#!/bin/perl
use strict;
use warnings;
my @array = ();
foreach my $i (0..10) {
push @array, [rand(1000), int(rand(3))];
}
foreach my $i (@array) {
print "@$i\n";
}
print "\n\n================\n\n";
print @{@array[1..3]};
print "\n\n================\n\n";