#!/usr/bin/perl use strict; defined ($ARGV[1]) or die "Usage: machine.pl \n"; my ($L, $l, $columns, $i, $h, $pain_in_butt, $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 = 0; 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; # was -1 print ("\nlength is $L\n"); $l = $L + ($columns - ($L % $columns)); print ("mod length is $l\n"); if (($L % $columns) == ($columns - 1) || (($L % $columns) == 0)) { $l = $L; } print ("\nlength is $L\n"); print ("mod length is $l\n"); $i = 0; $h = 0; for ($h = 0; $h < $L; $h++) # was $h <= $L { $outfile[$h] = $infile[$i]; print L ("when h is $h, i is $i and outfile[h] is $outfile[$h]\n"); $i = $i + $columns; if (($i > ($L - 1)) && ($i < $l)) { # was $i > $L and was $i <= $l $i = $i + ($columns); } if (($i >= $l) && ($i > $L)) { $i = $i - ($l - 1); } } for ($i = 0; $i < $L; $i++) { # was $i <= $L if (($i % 70) == 0 && ($i != 0)) { print O ("\n"); } print O ($outfile[$i]); } close (IN); close(O); close(L);