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!


In reply to How to print a text document to RTF document by mdavies23

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.