mdavies23 has asked for the wisdom of the Perl Monks concerning the following question:
My program takes in an RTF document and can print in plain text but I am having trouble printing to a RTF document. Here is my code so far:
#!/usr/bin/perl use Data::Dumper 'Dumper'; use strict; use RTF::Parser; use RTF::TEXT::Converter; use RTF::Writer; #my $tokenizer = RTF::Tokenizer->new( file => "123456.rtf" ); die "usage: $0 input output\n" unless @ARGV == 2; my $infile = shift; my $outfile = shift; open my $fh, "<", $infile; open my $output, ">", $outfile; my $string; my $rtf = RTF::Writer->new_to_file($output); my $object = RTF::TEXT::Converter->new (output => \$string); $object->parse_stream( $fh ); chomp $string; my @un = split("\n", $string); my @sorted = sort { my @fields_a = split ' ' , $a; my @fields_b = split ' ', $b; chomp($a, $b); $fields_a[0] <=> $fields_b[0]; if($fields_a[1] || $fields_b[1] eq 'ERROR'){ $rtf->prolog(); $rtf->print($fields_a[1]); } } @un; $rtf->close; close $fh; close $output;
Basically if the field in the array says "ERROR" I want to print that to a RTF document. Any help would be much appreciated!
|
|---|