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语言入门
输入与输出
103
会在正常输出之前被输出。比如你的程序要打印一行常规文字,然后做一个除以零的
数学计算,那么与除以零相关的错误信息会先被打印到终端,之后再打印常规文字。
打开文件句柄
到目前为止,你已经看到过
Perl
提供的三种默认文件句柄——
STDIN
STDOUT
以及
STDERR
——它们都是由产生
Perl
进程的父进程(通常是
shell
)自动打开的文件或设
备。当你需要其他文件句柄时,请使用
open
操作符告诉
Perl
,要求操作系统为你的
程序和外界架起一道桥梁。来看几个具体例子:
open CONFIG, 'dino';
open CONFIG, '<dino';
open BEDROCK, '>fred';
open LOG, '>>logfile';
第一行会打开名为
CONFIG
的文件句柄,让它指向文件
dino
。换句话说,它会打开
(已存在的)文件
dino
,文件中的任何内容都能从文件句柄
CONFIG
被读到我们的程
序中来。这和利用
shell
的重定向(例如
<dino
这样的写法)将文件内容经
STDIN
入程序的做法相似。事实上,第二行正好用到了这样的技巧,它和第一行所做的事完
全相同,只不过用了小于号来声明“此文件只是用来读取的,而非写入”。打开文件
句柄的默认模式就是读取数据。
选择读取操作作为默认行为是出于安全的考虑。随后我们会在第
15
章详细介绍文件
名中可以用到的其他几个魔法字符。如果
$name
里是由用户提供的文件名,那么直
接使用变量
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