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版)
26
1
我该如何编译
Perl
程序?
只需要直接运行它就可以了。只此一步,
perl
解释器能一次完成编译和运行这两个
动作:
$
perl my_program
运行程序时,
Perl
内部的编译器会先载入整个源程序,将之转换成内部使用的
bytecodes
(字节码),这是一种
Perl
在内部用来表示程序语法树的数据结构。然后
交给
Perl
的字节码引擎执行。所以,如果在第
200
行有个语法错误,那么在开始运行
第二行代码之前,
Perl
就会报告这个错误。如果你的程序中有一个运行
5 000
次的循
环,它只会被编译一次,然后每次循环都以最快的速度运行。除此之外,为了提高易
读性,不论你用多少注释和空白,它们都不会影响运行时(
runtime
)的速度。你甚至
可以使用完全由常量组成的算式,它的值只会在程序开始时被计算一次,哪怕它是在
某个循环中,也只被计算一次,然后在后续的执行中复用计算结果。
不用说,编译是要花时间的——所以如果只是为了迅捷地完成某个简短任务而去运行
一个冗长的包含其他各种任务代码的
Perl
程序,会显得效率低下,因为花在编译上的
时间可能会比运行时间还要长。不过
Perl
编译器的运行速度非常快,通常编译时间只
占运行时间的极少部分而已。
要是把编译后的字节码存储起来,能否节省编译时间?或者更进一步说,能否将字节
码转换成另一种语言,比如
C
语言,然后再进行编译?好吧,其实以上两种做法在某
些情况下都是可行的,不过老实说这么做并没什么好处,程序不会因此变得更易于使
用、维护、调试或安装,甚至(由于某些技术性因素)还会让程序运行得更慢。 ...
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