#! perl
use strict;
use warnings;
use Data::Dump;
my @matrix;
my $row = 0;
push @{$matrix[$row++]}, split while <DATA>;
dd @matrix;
print 'element at col 3, row 2 is ', get_element(\@matrix, 3, 2), "\n"
+;
sub get_element
{
my ($matrix_ref, $col, $row) = @_;
return $matrix_ref->[$row - 1][$col - 1];
}
__DATA__
20 30 40
60 70 80
90 100 49
Output:
23:50 >perl 548_SoPW.pl
([20, 30, 40], [60, 70, 80], [90, 100, 49])
element at col 3, row 2 is 80
23:50 >
Update: A simpler syntax for populating the array:
my @matrix;
push @matrix, [ split ] while <DATA>;
Hope that helps,
|