Advertisement
overloop

table.pl

Jan 26th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.59 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. if (scalar(@ARGV)<3) {
  4.     print "usage: table.pl rows cols file\n";
  5.     if (scalar(@ARGV)==0) {
  6.         exit 0;
  7.     } else {
  8.         exit -1;
  9.     }
  10. }
  11.  
  12. my ($rows,$cols,$file) = @ARGV;
  13.  
  14. my @lines = ();
  15. open INPUT,"<",$file;
  16. while (my $line = <INPUT>) {
  17.     chomp($line);
  18.     push(@lines,$line);
  19. }
  20. close INPUT;
  21.  
  22. my $lines_length = scalar(@lines);
  23. my $sep = "\t";
  24. my $blank = " ";
  25.  
  26. for (my $i=0;$i<$rows;$i++) {
  27.     for (my $j=0;$j<$cols;$j++) {
  28.         my $k = $i*$cols + $j;
  29.         if ($j<$lines_length) {
  30.             print $lines[$k];
  31.         } else {
  32.             print $blank;
  33.         }
  34.         print $sep;
  35.     }
  36.     print "\n";
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement