Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- if (scalar(@ARGV)<3) {
- print "usage: table.pl rows cols file\n";
- if (scalar(@ARGV)==0) {
- exit 0;
- } else {
- exit -1;
- }
- }
- my ($rows,$cols,$file) = @ARGV;
- my @lines = ();
- open INPUT,"<",$file;
- while (my $line = <INPUT>) {
- chomp($line);
- push(@lines,$line);
- }
- close INPUT;
- my $lines_length = scalar(@lines);
- my $sep = "\t";
- my $blank = " ";
- for (my $i=0;$i<$rows;$i++) {
- for (my $j=0;$j<$cols;$j++) {
- my $k = $i*$cols + $j;
- if ($j<$lines_length) {
- print $lines[$k];
- } else {
- print $blank;
- }
- print $sep;
- }
- print "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement