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

Perl语言入门(第8版)

by Randal L. Schwartz, brian d foy, Tom Phoenix
October 2022
Beginner to intermediate content levelBeginner to intermediate
390 pages
7h 5m
Chinese
Southeast University Press
Content preview from Perl语言入门(第8版)
44
2
后面需要紧跟着其他合法的变量名字符,即字母、数字或下划线时,
Perl
就无从判
断,需要引入免除歧义的写法。
解决思路就是隔离。和在
shell
下的写法相同,我们可以在变量名两边加上花括号,明
确表示需要内插的变量。或者在变量名结尾断开,另外采用字符串连接操作符连接:
$what = "brontosaurus steak";
$n = 3;
print "fred ate $n $whats.\n"; #
不是牛排,而是变量
$whats
的值
print "fred ate $n ${what}s.\n"; #
内插的是
$what
print "fred ate $n $what" . "s.\n"; #
效果同上
print 'fred ate ' . $n . ' ' . $what . "s.\n"; #
另一种折腾的写法
如果在变量名后紧跟的字符是左方括号或左花括号,请使用反斜线转义。如果
跟的是撇号或者连着的两个冒号,也请使用反斜线转义,或者直接使用花括号
隔离。之后我们会加以说明,不转义的写法还有另外的意义。
用代码点创建字符
有时候我们需要输入键盘上没有的那些字符,比如
é
å
α
或者
$barney = "fred ate a $meat"; # $barney is now "fred ate a "
You see more about this later in this chapter when we introduce the undef value. ...
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.
Start your free trial

You might also like

Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Run Llama-2 Models

Run Llama-2 Models

Federico Castanedo

Publisher Resources

ISBN: 9787576602036