Skip to Content
Perl语言入门
book

Perl语言入门

by Randal L. Schwartz, brian d foy, Tom Phoenix
August 2018
Beginner to intermediate
382 pages
7h 14m
Chinese
Southeast University Press
Content preview from Perl语言入门
用正则表达式进行匹配
155
在这里例子里,根据
Perl
处理
$_
中字符串以及模式匹配中字符串的方式不同,你可
能会得到不同的结果。如果程序源代码用
UTF-8
保存,但输入的字符串是
Latin-9
码的,会发生什么?在
Latin-9
里面,字符
Œ
的内部编码为
0xBC
,而它的小写版
œ
的内部编码为
0xBD
。在
Unicode
里面,
Œ
的代码点是
U+0152
,而
œ
的代码
点是
U+0153
。在
Unicode
里,
U+0OBC
表示
¼
,它并没有什么小写版本。如果你
$_
中输入的是
0xBD
并且
Perl
将正则表达式作为
UTF-8
字符串来处理的话,是不
会得到预想的结果的。不过,你可以添加
/l
修饰符强制
Perl
按照本地化设定的规则
解析正则表达式的含义:
use v5.14;
my $OE = chr( 0xBC ); #
明确取得我们所讲的那个字符
$_ = <STDIN>;
if (/$OE/li) { #
好多了
print "Found $OE\n";
}
如果希望始终按
Unicode
语义阐释,做法同上面
Latin-1
的例子一样,在正则表达式
末尾明确写上
/u
修饰符:
use v5.14;
$_ = <STDIN>;
if (/Œ/ui) { #
现在使用
Unicode
print "Found Œ\n";
}
是不是觉得头很大?没错,谁都不喜欢这么复杂的情形,不过
Perl
在这里已经尽其所
能把该做的事都处理好了。要是能推倒历史重新来过的话,也许就不会闹出这么多麻 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

计算机科学导论:跨学科方法

计算机科学导论:跨学科方法

罗伯特 塞奇威克, 凯文 韦恩
Perl语言入门(第8版)

Perl语言入门(第8版)

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787564177911