#!/usr/bin/perl use strict; defined ($ARGV[1]) or die "Usage: machine.pl \n"; my ($L, $l, $columns, $rows, $i, $h, $j, $buf, @infile, @outfile, $c, $logfile, $doclength); $logfile = "col-trans.log"; open (O,">".$ARGV[1]) or die "Output file open failed: $!\n"; open (L,">".$logfile) or die "Output file open failed: $!\n"; open(IN,"$ARGV[0]") || die "Sorry. Couldn't open: $!\n"; print ("number of columns? "); $columns = ; $doclength = 1; while (read (IN, $buf, 1)) { if (($buf eq "\t") || ($buf eq " ")) { $buf = "_"; } if ($buf ne "\n") { $infile[$doclength] = $buf; print L ("when doclength is $doclength, buf is $buf\n"); $doclength++; } } $L = $doclength; if (($L % $columns) == 0) { $l = $L; $rows = $L / $columns; } else { $l = $L + ($columns - ($L % $columns)); $rows = $l / $columns; } print L ("\nlength is $L\n"); print L ("mod length is $l\n"); print L ("\ncolumns is $columns\n"); print L ("rows is $rows\n"); $i = 1; $h = 1; $j = 0; for ($h = 1; $h <= $rows; $h++) { for ($i = 1; $i <= $columns; $i++) { $j++; $outfile[$h][$i] = $infile[$j]; } } $i = 1; $h = 1; $j = 0; for ($i = 1; $i <= $columns; $i++) { for ($h = 1; $h <= $rows; $h++) { $j = $j + 1; if (($j % 70) == 0 && ($j != 0)) { print O ("\n"); } print O ($outfile[$h][$i]); } } close (IN); close(O); close(L);