Hello mdavies23,
Welcome to the monastery. Very I have not spend time to try to resolve your question but with a quick look that I see I can recommend a few things.
First of all please provide us sample of Input file/data and also the expected format that you want to have. By doing this we can play around and we can match your expectations.
Regarding the code its self. Every time you open a file handle or close one use die or warn.
I do not see on your code closing the file handles.
Provide us all the requested information and we will be more than happy to assist you.
Update: It seems that your solution comes from question rtf to txt conversion. So I combine it with the module RTF::Writer and the full code is provided bellow. I used an input file as the <DATA> that I provide bellow.
#!usr/bin/perl
use strict;
use warnings;
use RTF::Writer;
use Data::Dumper;
use RTF::Tokenizer;
die "usage: $0 input output\n" unless @ARGV == 2;
my $infile = shift;
my $outfile = shift;
my $tokenizer = RTF::Tokenizer->new();
$tokenizer->read_file($infile);
my ( $token_type, $argument, $parameter );
{
# reduce bogus warnings
no warnings 'uninitialized';
# get past the header
( $token_type, $argument, $parameter ) =
$tokenizer->get_token() until
($token_type eq 'control' and $argument eq 'pard');
}
my @final;
while ($token_type ne 'eof'){
( $token_type, $argument, $parameter ) = $tokenizer->get_token();
push @final, $argument if $token_type eq 'text';
}
my $rtf = RTF::Writer->new_to_file($outfile);
$rtf->print(\@final);
$rtf->close;
__END__
{La dame p\'2eLa dameToc toc Il a ferm la porteLes lys du jardin sont
+fltrisQuel est donc ce mort qu'on emporteTu viens de toquer sa porte
+Et trotte trotteTrotte la petite souris Guillaume Apollinaire, Alcool
+sVocabularytoc (n\'2em\'2e) tap; knocklys (n\'2em\'2e) lilyfltrir (
+v\'2eitr\'2e) to wilt; for a flower or beauty to fade;for a plant to
+ withermort (adj\'2e, here used as a masc\'2e noun) deademporter (v\
+'2etr\'2e) to take a person or thing [somewhere];to take[out/away/et
+c\'2e] or carry[away] a thingtoquer (v\'2eitr\'2e) to tap; to knockt
+rotter (v\'2eitr\'2e) to trot; to scurrysouris (n\'2ef\'2e) mouse\'
+46ree TranslationClick click He closed the door / Garden lilies faded
+ / Which body
is today// You just tapped on the door / And tip toe / Taps the little
+
mouse Translation Sean M\'2e Burke, 2001}
Of course if you want to get a formatted output you have to spend some time and use the functions mentioned on the RTF::Writer/FUNCTIONS module.
Hope this helps, BR.
Seeking for Perl wisdom...on the process of learning...not there...yet!
|