perl-i18n

RE: Reading UTF-8 file

2003-05-23 12:03:03
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: anil(_dot_)joshi(_at_)ascentialsoftware(_dot_)com
[mailto:anil(_dot_)joshi(_at_)ascentialsoftware(_dot_)com]
Sent: Friday, May 23, 2003 2:58 PM
To: perl-i18n(_at_)perl(_dot_)org
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
<Prev in Thread] Current Thread [Next in Thread>