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语言入门
36
2
双引号内字符串可以使用变量内插(
variable interpolated
)的写法,说白了就是在字
符串中附带变量,结果用变量内的值替换。由于还未谈到变量的概念,所以这部分内
容稍后解释。
字符串操作符
字符串可以用
.
操作符(没错,就是句点符号)拼接起来。两边的原始字符串都不会
因此操作而被修改,就像
2+3
的运算不会改变
2
3
一样。运算后得到一个更长的字
符串,可以继续用于其他运算或保存到某个变量中。来看具体例子:
"hello" . "world" #
等同于
"helloworld"
"hello" . ' ' . "world" #
等同于
'hello world'
'hello world' . "\n" #
等同于
"hello world\n"
要注意的是,连接运算必须显式使用串接操作符,而不像其他某些语言那样,把两个
字符串前后写在一起就算拼接。
还有个比较特殊的字符串重复操作符,记作小写的字母
x
。此操作符会将其左边的操
作数(也就是要重复的字符串)与它本身重复连接,重复次数则由右边的操作数(某
个数字)指定。来看具体例子:
"fred" x 3 #
"fredfredfred"
"barney" x (4+1) #
"barney" x 5
,亦即
"barneybarneybarneybarneybarney"
5 x 4.8 #
本质上就是
"5"x 4
,所以得
"5555"
最后一个例子有必要详加说明。因为重复操作符的左操作数必然是字符串类型,所 ...
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