perl 中的大写重音字符 [英] Uppercase accented characters in perl

查看:19
本文介绍了perl 中的大写重音字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在perl中将重音字符变成大写,

Is there a way to uppercase accented characters in perl,

my $string = "éléphant";

print uc($string);

所以它实际上打印了 ÉLÉPHANT ?

So that it actually prints ÉLÉPHANT ?

我的 perl 脚本以 ISO-8859-1 编码,$string 以相同编码打印在 xml 文件中.

My perl script is encoded in ISO-8859-1 and $string is printed in an xml file with the same encoding.

推荐答案

perl 只懂 US-ASCII 和 UTF-8,后者需要

perl only understands US-ASCII and UTF-8, and the latter requires

use utf8;

如果您想将文件保留为 iso-8859-1,您需要对文本进行显式解码.

If you want to keep the file as iso-8859-1, you'll need to decode the text explicitly.

use open ':std', ':encoding(locale)';
use Encode qw( decode );

# Source is encoded using iso-8859-1, so we need to decode ourselves.
my $string = decode("iso-8859-1", "éléphant");
print uc($string);

但最好将脚本转换为 UTF-8.

But it's probably better to convert the script to UTF-8.

use utf8;  # Source is encoded using UTF-8
use open ':std', ':encoding(locale)';

my $string = "éléphant";
print uc($string);

如果要打印到文件,请确保在打开文件时使用 :encoding(iso-8859-1)(无论使用哪种替代方法).

If you're printing to a file, make sure you use :encoding(iso-8859-1) when you open the file (no matter which alternative you use).

这篇关于perl 中的大写重音字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆