for(my $i = 0; $i < @filecontents; $i++)
{
# place each line in file
# into another array
#
@line = split(/\,/, $filecontents[$i]);
# XXX ^------ do you really mean comma?
####
# [] constructs an anonymous array, so we use that.
# several ways to do it - choose any (not all :-)
my $anon_array = []; # gimme an anonymous array and
# assign it to $anon_array
@$anon_array = @line; # assign to the anonymous array
push(@matrix, $anon_array);
# shortcut:
$anon_array = [ @line ];
push(@matrix, $anon_array);
# compacting further: split returns a list, use that
# to populate an anonymous array on the fly, push that
# (the SCALAR value which is an array reference) onto
# the array @matrix
push(@matrix, [split(/\s+/, $filecontents[$i])]);
}
####
my @matrix;
while () {
chomp; # you forgot that - remove trailing newline char
push(@matrix, [split]);
}
####
#!/usr/bin/perl
use strict;
my @matrix;
while (<>) {
chomp; # you forgot that - remove trailing newline char
push(@matrix, [split]);
}
####
$#ARGV = 0; # @ARGV now holds only one element (the first at index 0)
####
print $matrix[7]->[4],"\n";