Re: RTF and UTF-8 files in Perl
- From: "Matt Garrish" <matthew.garrish@xxxxxxxxxxxx>
- Date: Sun, 30 Oct 2005 12:24:26 -0500
"V S Rawat" <VSRawat@xxxxxxxxxxxx> wrote in message
news:xn0e93zst5r39c000@xxxxxxxxxxx
> 1. How do I open a RTF file as input in Perl and read formatted
> ASCII text from it?
>
You don't. There's no such thing as formatted ASCII text. You could look
into a module such as RTF::Tokenizer if you want to parse apart the RTF file
and extract the text from it. If you want to know what formatting has been
applied you'll also need to check the formatting commands as you go.
> 2. How do I open a UTF-8 (Unicode) file as output in Perl and
> write Unicode text to it?
>
Assuming your data is not already utf8:
[untested]
use Encode;
open(my $out, '>:utf8', 'somefile.dat') or die "Could not open file: $!";
print $out Encode::encode('utf8', $mydata);
close($out) or die "Could not close file: $!";
Otherwise you could skip the encoding step.
Matt
.
- Follow-Ups:
- Re: RTF and UTF-8 files in Perl
- From: V S Rawat
- Re: RTF and UTF-8 files in Perl
- References:
- RTF and UTF-8 files in Perl
- From: V S Rawat
- RTF and UTF-8 files in Perl
- Prev by Date: FAQ 9.13 How do I edit my .htpasswd and .htgroup files with Perl?
- Next by Date: Re: Perl site - Elementary question
- Previous by thread: RTF and UTF-8 files in Perl
- Next by thread: Re: RTF and UTF-8 files in Perl
- Index(es):
Relevant Pages
|
|