Sunday, January 25, 2015

Read text file and print on console Perl

#!/usr/bin/perl
use strict;
use warnings;
use 5.010;

my $file = 'matrixin.txt';
my @data;
open( FILE, $file ) or die "Can't open file '$file': $!";
while( ) {
chomp;
my @row = split;
push @data, \@row;
}
close( FILE );

#Print output
for my $i (0..$#data)
{
for my $j (0..$#{$data[0]})
{
   print "$data[$i][$j]","\t";
}
   print "\n";
}

No comments: