in reply to matrix multiplication
my @mat1 = readmatrix ($first); my ($r1, $c1) = ($rows, $cols); ... sub readmatrix { my ($file) = @_; open(IN, "$file") || die "can't open file: $!\n"; while (defined (my $line = <IN>)) { my @tmp = split(' ', $line); $cols = scalar @tmp; $rows++; push (@AoA, [@tmp]); } close IN; }
That would probably be better as:
my ( $r1, $c1, @mat1 ) = readmatrix( $first ); ... sub readmatrix { my ( $file ) = @_; open my $IN, '<', $file or die "can't open file: $!\n"; my @AoA; while ( <$IN> ) { push @AoA, [ split ]; } return $., scalar @{ $AoA[ -1 ] }, @AoA; }
|
|---|