I have created a program that takes in a RTF document, sorts it, and then outputs another RTF document. The problem is that the input file is around 400kb and the output file is 3000 kb. I noticed that the old RTF has the formatting stated at the top and the new RTF has the formatting attached to every line because I am looping through the array with all the text. Here is an example of the code:

my @warning_array; print "Enter input file (.RTF)\n"; $infile = <STDIN>; chomp($infile); print "Enter output file (.RTF)\n"; $outfile = <STDIN>; chomp($outfile); #Open selected files open my $fh, "<", $infile; open my $output, ">", $outfile; #New RTF writer my $rtf = RTF::Writer->new_to_file($outfile); no warnings 'uninitialized'; #New RTF -> text converter my $object = RTF::TEXT::Converter->new (output => \$string +); $object->parse_stream( $fh ); #Create the array and push the text into it my @un = split("\n", $string); #Sort the array my @sorted = sort { my @fields_a = split / / , $a; my @fields_b = split / /, $b; chomp($a, $b); $fields_a[1] cmp $fields_b[1] || $fields_a[0] <=> $field +s_b[0]; } @un; #SEARCH FOR WARNINGS @warning_array = grep {$_ =~ 'WARNING'} (@sorted); foreach(@warning_array){ if ($_ =~ "WARNING"){ $rtf->prolog( 'title' => "Color Test", 'colors' => [ undef, [0,0,0], # 1 - black [255,0,0], # 2-red [0,255,0], # 3-green [0,0,255], # 4-blue [255,128,0], # 5-orange [255,255,0], # 6-yellow ], ); #PRINT WARNINGS IN YELLOW $rtf->printf( \'{\fs20\lang1036\noproof\cf5\chshdn +g10000\chcbpatN\chcfpatN\cbN %s} \par ', "$_"); } } }

Is there any way to make the output smaller?


In reply to RTF size issues 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.