#! /usr/bin/perl -w
use strict;

# Open the external file
open my $MAT, '<', './matrix.dat';
my @mat;
my $nrow = 0;
my $ncol0;
while ( <$MAT> ) {

    next if ( /^\s*$/ );
    my @row = split ' '; 
    chomp @row;
    push @mat, \@row;
    
    if ( $nrow == 0 ) {
	$ncol0 = scalar @row;
    } else {
	die "Not a matrix\n" unless ( scalar @row == $ncol0 );  
    }
    $nrow++;
}
close $MAT;
print "Found a $nrow X $ncol0 matrix.\n"; 
