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版)
目录操作
241
Perl
内置的
glob
并非唯一选择。我们可以用
File::Glob
模块提供各式兼容和
扩展的文件名通配。
文件名通配的隐式语法
虽然我们一直在介绍文件名通配,也介绍了
glob
操作符的用法,可在许多进行文件
名通配处理的程序里你可能完全看不到
glob
这个词。为什么呢?那是因为大部分过
去写的程序都是在
glob
操作符出现之前写的。它们使用尖括号语法来调用此功能,
看起来就跟读取自文件句柄差不多:
my @all_files = <*>; #
效果和这样的写法完全一致:
my @all_files = glob "*";
Perl
会把尖括号内出现的变量替换成它的值,类似于双引号内字符串的变量内插,这
表示在进行文件名通配之前,
Perl
会把变量展开为它的当前值:
my $dir = '/etc';
my @dir_files = <$dir/* $dir/.*>;
此处,因为
$dir
会被展开成它当前的值,所以最终会取得指定目录下的所有文件,
不管文件名称是以点号开头的还是不以点号开头的。
这样说来,假如尖括号既表示从文件句柄读取又代表文件名通配操作,那
Perl
又是如
何判断取舍的呢?嗯,因为合理的文件句柄必须是严格意义上的
Perl
标识符,所以如
果尖括号内是满足
Perl
标识符条件的,就作为文件句柄来读取;否则,它代表的就是
文件名通配操作。比如:
my @files = <FRED/*>; #
文件名通配操作
my @lines = <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

Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Perl语言入门

Perl语言入门

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 9787576602036