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语言入门
标量数据
43
在实践中,建议用
say
,因为按键次数少,效果好。但在本书中,我们仍将延续使
print
,让还在使用
5.8
版的读者可以直接运行示例程序。
字符串中的标量变量内插
一般我们用双引号圈引字符串,是希望把其中的变量替换为变量当前的内容,从而成
为新的字符串。这个转变的过程我们称之为变量内插,来看示例:
$meal = "brontosaurus steak";
$barney = "fred ate a $meal"; # $barney
变为
"fred ate a brontosaurus steak"
$barney = 'fred ate a ' . $meal; #
效果相同的另一种写法
正如上面最后一行所示,不用双引号一样可以得到相同结果,但就书写和可读性来
说,显然不如变量内插的方式直观方便。变量内插有时候也被称作双引号内插,因为
只有在双引号内部才可以这么做,在单引号中不行。
Perl
里面还有其他内插方式,之
后我们会逐一介绍。
如果标量变量从未被赋值,内插时将使用空字符串替换:
$barney = "fred ate a $meat"; # $barney
变为
"fred ate a "
稍后在本章介绍空值
undef
的时候,将看到更多类似的情况。
如果内插时单单就是变量本身,不写双引号当然也行:
print "$fred"; #
多余的双引号
print $fred; #
合理写法
形式上,在单个变量两边加上双引号表示变量内插并不算错,但既然不是要构造更长
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