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语言入门
42
2
下面这两行的效果也完全相同:
$barney = $barney * 3;
$barney *= 3;
在内部实现上,复合赋值操作符就地更新原来的变量值,这样效率更高。传统赋值操
作符则需要先计算表达式,再把求值后的结果写入变量。
还有一个常见的用于连接字符串的赋值操作符
.
,其对应的复合赋值操作符是
.=:
$str = $str . " "; #
追加空格到
$str
末尾
$str .= " "; #
效果同上
几乎所有的复合赋值操作符都像这样用。比如,乘幂操作符可以改成
**=
,所以
$fred
**= 3
的意思就是说,“将
$fred
里的值自乘
3
次(也就是取三次方),再存
$fred
”。
print
输出结果
若程序运行完了什么消息都没有,我们就无从判断运行过程中是否一切正常。我们可
以用
print
操作符输出内容到外部。它接受标量值作为参数,然后不经修饰地将它传
送到标准输出(
standard output
)。除非另外设置,默认情况下标准输出设备就是你
的终端显示屏。比如:
print "hello world\n"; #
输出
hello world
,后面接着换行符
print "The answer is ";
print 6 * 7;
print ".\n";
交给
print
输出的也可以是一系列以逗号隔开的值:
print "The answer is ", 6 * 7, ".\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