Yeah, I know the differences between a list and an array. And I know that split returns a list, but it is slightly more tricky than that. If you do this:
my $c = qw / 4 6 8 90/;
$c's value becomes the last element of the list (90). But if you do this:
$c = split / /, "the quick brown fox";
$c is now 4, the number of elements of the array (I think this would also trigger a warning that @_ may be overwritten). But if you do this:
$c = (split / /, "the quick brown fox")[2];
now this behaves as an anonymous array et $c is assigned to "brown" (and there no longer any warning, because Perl sort of built an anonymous array). And if you do this:
$c = [split / /, "the quick brown fox"];
$c's value is now something like "ARRAY(0x80359d10)", i.e. an array reference. and you need something like this:
print $c->[2];
to print the third element of the array. This is really an array ref, not an array.
|