Since your e-Reader will most likely have a screen whose display width does not conveniently align with these line breaks, text will be brutally choppy and difficult to read, appearing like this:
So
then the guy went to the place with the
guy
and some more stuff happened. Good times,
man.
Good times.
Behold the power of Perl!
#!/usr/local/bin/perl
my $parsedFile = $ARGV[0];
my $outputFile = $ARGV[1];
my @outContents;
open FD, $parsedFile or die "Can't open input file: $!";
LOOP: while ([FD]) {
my $line = $_;
if (/^$/) {
push(@outContents, $line);
} elsif (length($line) > 66) {
$line =~ chomp($line);
$line = $line . " ";
} else {
$line = $line . "\n";
}
push(@outContents, $line);
}
open FD, ">$outputFile" or die "Can't open output file: $!";
foreach $line (@outContents) {
print FD $line;
}
close FD;
Note: the [FD] in the while loop should actually be enclosed in angle brackets, stupid Blogger.
You're welcome.
1 comment:
I shouldn't be using ARGV for the input to this program. That's a C-ism. Actual perl people would use shift or @_ or such.
But, y'know, I'm a C kinda guy.
Post a Comment