in reply to padding variable length documents

If you're asking how to take a file and pad all of the lines out to the same width, this piece might work for you (untested):
#!/usr/bin/perl -w open(FILE, "+</tmp/foo.txt") || die "Can't open: $!"; $l=0; @lines=map { chomp;$l=$l<length()?length():$l;$_ } <FILE>; seek(FILE, 0, 0) || warn "Seek: $!"; for(@lines) { printf FILE "%-${l}s\n", $_; }

Replies are listed 'Best First'.
Re: Re: padding variable length documents
by Anonymous Monk on May 17, 2001 at 19:05 UTC
    this is what I have so far but it still doesn't work #!/usr/bin/perl my $maxlength = 80; my $wordlength; my $bufferlength; open(FILE, ">padthis.txt") or die "cant open $!"; while (<>){ chomp; @array = split (" ", $_); foreach $word (@array){ $wordlength = length($word); } $bufferlength = $maxlength - $wordlength; print $bufferlength; #for ($buff = 0; <= $bufferlength; $buff++); for ($i=0;$i<=$bufferlength; $i++) { foreach $word (@array) { print ($word = $word + "*"); print FILE; } } } close FILE;