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版)
66
3
哪种更方便得看你的具体需求。够用就好。
标量上下文与列表上下文
这是本章最重要的一节,甚至也是本书最重要的一节。就算说你的
Perl
水平基本取决
于对本节内容的了解程度,也毫不夸张。所以,如果之前你都是随便翻阅的话,现在
该集中注意力了。
这并不是说本节有多么难懂,其实这里的概念非常简单:同一个表达式出现在不同的
地方时会有不同的意义。你应该不会陌生,因为在自然语言里,这种情况随处可见。
以英语为例,假如有人问你单词“
read
”代表什么意思,你一定很难简单回答,因为
用在不同的地方,表达的意思可能会不同。除非你知道上下文(
context
),否则没法
确认它的准确含义。
所谓上下文,指的是如何使用表达式。实际上你已经看到过许多针对数字和字符串的
上下文操作了。比如按照数字进行操作时得到的就是数字结果,而按照字符串进行操
作时返回的则是字符串结果。并且,起到决定性因素的是操作符,而不是被操作的各
种变量或直接量。
2*3
中的
*
作为对数字的乘法运算符号,得到的结果就是数字
6
2
×
3
中的
×
则表示字符串重复操作,所以得到的结果是字符串
222
。这就是上下
文在起作用。
Perl
在解析表达式时,要么希望它返回一个标量值,要么希望它返回一个列表值。
表达式所在的位置,
Perl
期望得到什么,那就是该表达式的上下文:
42 + something #
这里的
something
必须是标量
sort something #
这里的
something
必须是列表
这就像我们平时说的口语。如果我犯了一个语法错误,你会马上发现,因为按照语 ...
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