Skip to Content
Perl语言入门(第8版)
book

Perl语言入门(第8版)

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2022
Beginner to intermediate
390 pages
7h 5m
Chinese
Southeast University Press
Content preview from Perl语言入门(第8版)
用正则表达式处理文本
189
把这个程序与我们在上一节使用的程序相比,会发现这两者十分相似。通过命令行选
项就能完成这么一大堆事情,写起来又轻便,是不是很棒?
习题
以下习题答案参见第
321
页上的“第
9
章习题解答”一节:
1. [7]
建立一个模式,无论
$what
的值是什么,它都可以匹配三个
$what
变量的
内容连在一起的字符串。也就是说,如果
$what
的值是
fred
,那么你的模式应
该匹配
fredfredfred
;若
$what
的值为
fred|barney
,那么你的模式应该匹配
fredfredbarney
barneyfredfred
barneybarneybarney
或许多其他组合。(提
示:你应该在模式测试程序的开头放上类似
my $what = 'fred|barney';
这样的
语句。)
2. [12]
写个程序来复制并修改指定的文本文件。在副本里,此程序会把出现字
符串
Fred
(不区分大小写)的每一处都换成
Larry
(也就是
Manfred Mann
ManLarry Mann
)。输入文件名应该在命令行上指定(不询问用户),输出文
件名则是本来的文件名加上
.out
3. [8]
修改前一题的程序,把所有的
Fred
换成
Wilma
并把所有的
Wilma
Fred
。如果输入的是
fred&wilma
,那么正确的输出应是
Wilma&Fred
4. [10]
附加题:写个程序,把你目前写过的所有程序都加上版权声明,也就是加上 ...
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

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036