#!/usr/bin/perl use warnings; use strict; use File::Stream; my $m=3; my $n=4; my $filehandle; open ($filehandle, '<', "testfile") || die "can't open the testfile"; my $stream = File::Stream->new($filehandle); $/ = qr/\s+/; my @a; my @ia; my @ja; my $nnz=1; my $x=0; my $y=0; my $value; while ($value=<$stream>) { $value=~s/\s//g; #because chomp doesn't work with File::Stream $x++; if ($y==0 or $x>$n) { $x=1; $y++; push @ia,$nnz; } if ($value) { push @a, $value; push @ja, $x; $nnz++; } } push @ia,$nnz; if ($y!=$m and $x!=$m) { print "Wrong number of values in array data\n"; } print 'A= [ ', join(' ',@a),"]\n"; print 'IA= [ ', join(' ',@ia),"]\n"; print 'JA= [ ', join(' ',@ja),"]\n";