G
Gary Schenk
I try to use Perl in my work to solve repetitive tasks. I am
self-taught so far, with no mentor to badger with questions, so
I now badger the group. My apologies in advance.
I have an immense text file, with very long lines, sometimes over
900 characters long. I would like to format this so that the
lines are around 77 characters. I have been cutting out small
bits, reformatting the lines in Notepad, then export these
smaller text files into a CADD program. This is time consumming
and very tedious. An obvious job for Perl. I thought it would be
an easy regexp exercise, but keeping the words in one piece is
beyond my abilities right now. The Unix fmt command didn't help,
either.
I discovered Text::Autoformat. I have not been able to get it to
work. I get a usage error. I have Googled trying to find
examples of usage, and read up on it on CPAN, but I don't get
it. It seems as though people use it to format simple strings to
STDOUT. I want to format files.
Could someone point me in the right direction to getting this
code to work? I'm missing something terribly basic, I know. I
need a nudge in the right direction.
This is the latest version of the program:
#!/usr/bin/perl -w
use Text::Autoformat;
print "\n\nEnter a file to convert, or 'q' to quit: ";
chomp( $input = <STDIN> );
if ( $input ne 'q' ) {
open( INPUT, "<$input" ) or die( "Can't open $input for
reading: $!" );
open( OUTPUT, ">output.txt" ) or die( "Can't open output.txt:
$!" );
my $fixed = autoformat( <INPUT>, { left => 1, right => 77, all
=> 1 } );
print OUTPUT $fixed;
}
else {
print "Bye!\n";
}
The most recent error message:
Usage: autoformat([text],[{options}]) at ./nfmt.pl line 12
Thanks.
self-taught so far, with no mentor to badger with questions, so
I now badger the group. My apologies in advance.
I have an immense text file, with very long lines, sometimes over
900 characters long. I would like to format this so that the
lines are around 77 characters. I have been cutting out small
bits, reformatting the lines in Notepad, then export these
smaller text files into a CADD program. This is time consumming
and very tedious. An obvious job for Perl. I thought it would be
an easy regexp exercise, but keeping the words in one piece is
beyond my abilities right now. The Unix fmt command didn't help,
either.
I discovered Text::Autoformat. I have not been able to get it to
work. I get a usage error. I have Googled trying to find
examples of usage, and read up on it on CPAN, but I don't get
it. It seems as though people use it to format simple strings to
STDOUT. I want to format files.
Could someone point me in the right direction to getting this
code to work? I'm missing something terribly basic, I know. I
need a nudge in the right direction.
This is the latest version of the program:
#!/usr/bin/perl -w
use Text::Autoformat;
print "\n\nEnter a file to convert, or 'q' to quit: ";
chomp( $input = <STDIN> );
if ( $input ne 'q' ) {
open( INPUT, "<$input" ) or die( "Can't open $input for
reading: $!" );
open( OUTPUT, ">output.txt" ) or die( "Can't open output.txt:
$!" );
my $fixed = autoformat( <INPUT>, { left => 1, right => 77, all
=> 1 } );
print OUTPUT $fixed;
}
else {
print "Bye!\n";
}
The most recent error message:
Usage: autoformat([text],[{options}]) at ./nfmt.pl line 12
Thanks.