Hi All,
I need some help with utf-8 string handling in Perl. I tried to trim utf-8
strings using Perl. Follow is the main portion of the codes, but it does not
work. Any help will be greatly appreciated.
Jenny
-----
open (DIC_OLD, "<:utf8", $tmp_file) || die "can not open $tmp_file: ! \n";
open (DIC_NEW, ">:utf8", $dictionary_file) || die "can not open
$dictionary_file: ! \n";
$max_len = 290; # the max # of characters can be displayed
while ($myline = <DIC_OLD>) {
chomp $myline;
#format: <phrase i="212" t="DNS Server 1"/>
if ($myline =~ /<phrase\s*i=/) { #skip headers
�...@col = split(/\"/, $myline);
if ( length($col[3]) > $max_len ) {
$tmp = $col[3];
$col[3] = substr($tmp, 0, ($max_len - 1)); # Trim the tail-end of the
string leaving
$myline = join("\"", @col);
}
print DIC_NEW "$myline\n";
}