RE: Reading UTF-8 file

[email protected] Fri, 23 May 2003 15:25:57 -0400
Newsgroups perl.i18n
Message-ID <0F2A05A54977F248982FF81EA9578CDB01AD6E6D@asc-msg-02.ascentialsoftware.com>
------_=_NextPart_001_01C32161.23026650
Content-Type: text/plain;
	charset="ISO-8859-1"

Thanks Mags,
I will try that out . However what I really wanted to test was the extent to
which utf-8 is supported in perl.
What effect use utf8 pragma has on reading of file and string related
functions

Anil


-----Original Message-----
From: Mags Doheny [mailto:[email protected]]
Sent: Friday, May 23, 2003 3:15 PM
To: [email protected]
Subject: Re: Reading UTF-8 file


Anil, try using "$ENV{LANG} = <some_ja_utf8_locale which is installed on
your
OS>" & same for $ENV{LC_ALL} instead of "use utf8", although you would need
to
ensure that substr is locale-sensitive, i'm not sure if it is....

hth,
mags.

[email protected] wrote:

> oops I goofed up while writing mail the correct script is following !! Not
> utf8-> before susstr
>
> #!/usr/local/bin/perl
> use utf8;
> open(LOGFILE,"test.txt") or die "Could not open test.txt";
> open(OUTFILE,"out.txt") or die "Could not open out.txt";
> for $line (<LOGFILE>){
>     $tt1 = substr($line,0,1);
>     print OUTFILE $tt1;
>     print OUTFILE "\n";
> }
> close LOGFILE;
> close OUTFILE;
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]
> Sent: Friday, May 23, 2003 2:58 PM
> To: [email protected]
> Subject: Reading UTF-8 file
>
> Hi all,
> as it always begins this is my first mail on this list and the question is
> very trivial one.
> I am trying to read a UTF-8 file that contains Japanaese and English
> characters I want to write first charater of each line in an output file.
>
> I am using following script. And I am using perl 5.6.1? It does not seem
to
> work. What I am missing?
>
> #!/usr/local/bin/perl
> use utf8;
> open(LOGFILE,"test.txt") or die "Could not open test.txt";
> open(OUTFILE,"out.txt") or die "Could not open out.txt";
> for $line (<LOGFILE>){
>     $tt1 = utf8->substr($line,0,1);
>     print OUTFILE $tt1;
>     print OUTFILE "\n";
> }
> close LOGFILE;
> close OUTFILE;
>
> I tried following syntax to open file how ever it seems that it is not
> supported in Perl 5.6.1
> open(LOGFILE,"<:utf8","test.txt") or die "Could not open test.txt";
> open(OUTFILE,">:utf8","out.txt") or die "Could not open out.txt";
>
> Thanks
> Anil

------_=_NextPart_001_01C32161.23026650--