没有合适的资源?快使用搜索试试~ 我知道了~
首页Perl高级编程技术探索
Perl高级编程技术探索
需积分: 10 3 下载量 187 浏览量
更新于2024-07-24
收藏 1.94MB PDF 举报
"高阶PERL应用技术" 《高阶PERL应用技术》是一本专注于Perl语言高级应用的教程,旨在帮助读者深化对Perl的理解并提升编程技巧。这本书不仅涵盖了Perl的基础知识,更深入探索了计算机科学中的复杂概念,并将这些概念转化为实际编程中的强大工具。 在书中,作者Mark Jason Dominus揭示了如何通过提高效率和性能来改变我们对技术的基本思考方式。他以第3章的缓存技术为例,展示了当技术能力提升到一定程度时,它如何影响我们的编程思维。全书的核心在于,它从计算机科学的深层原理出发,包括递归、迭代器、过滤器、记忆化、分区、数值方法、高阶函数、柯里化、快速排序、基于语法的解析、惰性求值以及约束编程等概念,将这些看似复杂的理论转化为适用于实际问题解决的方法。 例如,书中探讨了如何利用Perl进行高效文件系统交互、HTML处理、数据库访问、网络爬虫构建、排版、邮件处理、个人财务管理、文本大纲创建以及图表生成等任务。同时,作者还巧妙地解释了“作用域”与“持续时间”这两个编程概念之间的微妙差异,使得这些抽象概念变得更加清晰易懂。 通过阅读《高阶PERL应用技术》,读者不仅能掌握Perl的高级技术,还能提升解决问题的能力,学会如何将理论知识应用于实际项目。这本书不仅适合已经熟悉Perl基础的开发者,也对那些希望拓展视野、提升编程技艺的程序员有着极大的价值。它将帮助你在Perl的世界中达到更高的层次,成为真正的编程大师。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/6434161/bg10.jpg)
xvi
clippings mixed in. Lisp programmers go around making funny noises like ‘cons’
and ‘cooder,’ and they talk about things like the PC loser-ing problem, whatever
that is. They believe that Lisp is better than other programming languages, and
they say so, which is irritating. But now it is all okay, because now you do not
have to listen to the Lisp folks. You can listen to me instead. I will make sooth-
ing noises about hashes and stashes and globs, and talk about the familiar and
comforting soft reference and variable suicide problems. Instead of telling you
how wonderful Lisp is, I will tell you how wonderful Perl is, and at the end you
will not have to know any Lisp, but you will know a lot more about Perl.
Then you can stop writing C programs in Perl. I think that you will find it
to be a nice change. Perl is much better at being Perl than it is at being a slow
version of C. You will be surprised at what you can get done when you write Perl
programs instead of C.
All the code examples in this book are available from my web site at:
http://perl.plover.com/hop/
When the notation in the margin is labeled with the tag some-example, the
code may be downloaded from:
http://perl.plover.com/hop/Examples/some-example
The web site will also carry the complete text, an errata listing, and other items
of interest. Should you wish to send me email about the book, please send your
message to
mjd-hop@plover.com.
Every acknowledgments section begins with a statement to the effect that “with-
out the untiring support and assistance from my editor, Tim Cox, this book
would certainly never have been written”. Until you write a book, you will never
realize how true this is. Words fail me here; saying that the book would not
have been written without Tim’s untiring support and assistance doesn’t begin
to do justice to his contributions, his kindness, and his vast patience. Thank
you, Tim.
![](https://csdnimg.cn/release/download_crawler_static/6434161/bg11.jpg)
xvii
This book was a long time in coming, and Tim went through three assistants
while I was working on it. All these people were helpful and competent, so my
thanks to Brenda Modliszewksi, Stacie Pierce, and Richard Camp. “Competent”
may sound faint, but I consider it the highest praise.
Many thanks to Troy Lilly and Simon Crump, the production managers,
who were not only competent but also fun to work with.
Shortly before the book went into production, I started writing tests for the
example code. I realized with horror that hardly any of the programs worked
properly. There were numerous small errors (and some not so small), inconsis-
tencies between the code and the output, typos, and so on. Thanks to the heroic
eleventh-hour efforts of Robert Spier, I think most of these errors have been
caught. Robert was not only unfailingly competent, helpful, and productive,
but also unfailingly cheerful, too. If any of the example programs in this book
work as they should, you can thank Robert. (If they don’t, you should blame
me, not Robert.) Robert was also responsible for naming the MOD document
preparation system that I used to prepare the manuscript.
The contributions of my wife, Lorrie Kim, are too large and pervasive to
note individually. It is to her that this book is dedicated.
A large number of other people contributed to this book, but many of them
were not aware of it at the time. I was fortunate to have a series of excellent
teachers, whose patience I must sometimes have tried terribly. Thanks to Mark
Foster, Patrick X. Gallagher, Joan Livingston, Cal Lobel (who first taught me to
program), Harry McLaughlin, David A. J. Meyer, Bruce Piper, Ronnie Rabassa,
Michael Tempel, and Johan Tysk. Mark Foster also arrived from nowhere in the
nick of time to suggest the title for this book just when I thought all was lost.
This book was directly inspired by two earlier books: ML for the Working
Programmer, by Lawrence Paulson, and Structure and Interpretation of Computer
Programs, by Harold Abelson and Gerald Jay Sussman. Other important influ-
ences were Introduction to Functional Programming, by Richard Bird and Philip
Wadler, and Paradigms of Artificial Intelligence Programming, by Peter Norvig.
The official technical reviewers had a less rewarding job than they might have
on other projects. This book took a long time to write, and although I wanted to
have long conversations with the reviewers about every little thing, I was afraid
that if I did that, I would never ever finish. So I rarely corresponded with the
reviewers, and they probably thought that I was just filing their suggestions in the
shredder. But I wasn’t; I pored over all their comments with the utmost care, and
agonized over most of them. My thanks to the reviewers: Sean Burke, Damian
Conway, Kevin Lenzo, Peter Norvig, Dan Schmidt, Kragen Sitaker, Michael
Scott, and Adam Turoff.
While I was writing, I ran a mailing list for people who were interested in
the book, and sent advance chapters to the mailing list. This was tremendously
![](https://csdnimg.cn/release/download_crawler_static/6434161/bg12.jpg)
xviii
helpful, and I’d recommend the practice to anyone else. The six hundred and
fifty wonderful members of my mailing list are too numerous to list here. All
were helpful and supportive, and the book is much better for their input. A few
stand out as having contributed a particularly large amount of concrete mate-
rial: Roland Young, Damien Warman, David “Novalis” Turner, Iain “Spoon”
Truskett, Steve Tolkin, Ben Tilly, Rob Svirskas, Roses Longin Odounga, Luc
St-Louis, Jeff Mitchell, Steffen Müller, Abhijit Menon-Sen, Walt Mankowski,
Wolfgang Laun, Paul Kulchenko, Daniel Koo, Andy Lester, David Landgren,
Robin Houston, Torsten Hofmann, Douglas Hunter, Francesc Guasch, Ken-
neth Graves, Jeff Goff, Michael Fischer, Simon Cozens, David Combs, Stas
Bekman, Greg Bacon, Darius Bacon, and Peter Allen. My apologies to the many
many helpful contributors whom I have deliberately omitted from this list in the
interests of space, and even more so to the several especially helpful contributors
whom I have accidentally omitted.
Wolfgang Laun and Per Westerlund were particularly assiduous in helping
me correct errors for the second printing.
Before I started writing, I received valuable advice about choosing a publisher
from Philip Greenspun, Brian Kernighan, and Adam Turoff. Damian Conway
and Abigail gave me helpful advice and criticism about my proposal.
Sean Burke recorded my Ivory Tower talk, cut CDs and sent them to me,
and also supplied RTF-related consulting at the last minute. He also sent me
periodic mail to remind me how wonderful my book was, which often arrived
at times when I wasn’t so sure.
Several specific ideas in Chapter 4 were suggested by other people. Meng
Wong suggested the clever and apt “odometer” metaphor. Randal Schwartz
helped me with the “append” function. Eric Roode suggested the multiple list
iterator.
When I needed to read out-of-print books by Paul Graham, A. E. Sundstrom
lent them to me. When I needed a copy of volume 2 of The Art of Computer
Programming, Hildo Biersma and Morgan Stanley bought it for me. When I
needed money, B. B. King lent me some. Thanks to all of you.
The constraint system drawing program of Chapter 9 was a big project, and
I was stuck on it for a long time. Without the timely assistance of Wm Leler,
I might still be stuck.
Tom Christiansen, Jon Orwant, and Nat Torkington played essential and
irreplaceable roles in integrating me into the Perl community.
Finally, the list of things “without which this book could not have been
written” cannot be complete without thanking Larry Wall for writing Perl and
for founding the Perl community, without which this book could not have been
written.
![](https://csdnimg.cn/release/download_crawler_static/6434161/bg13.jpg)
1
The first “advanced” technique we’ll see is recursion. Recursion is a method of
solving a problem by reducing it to a simpler problem of the same type.
Unlike most of the techniques in this book, recursion is already well known
and widely understood. But it will underlie several of the later techniques, and
so we need to have a good understanding of its fine points.
1.1
Until the release of Perl 5.6.0, there was no good way to generate a binary numeral
in Perl. Starting in 5.6.0, you can use
sprintf("%b", $num), but before that the
question of how to do this was Frequently Asked.
Any whole number has the form 2k + b, where k is some smaller whole
number and b is either 0 or 1. b is the final bit of the binary expansion. It’s easy
to see whether this final bit is 0 or 1; just look to see whether the input number
is even or odd. The rest of the number is 2k, whose binary expansion is the
same as that of k, but shifted left one place. For example, consider the number
37 = 2 ·18 +1; here k is 18 and b is 1, so the binary expansion of 37 (100101)
is the same as that of 18 (10010), but with an extra 1 on the end.
How did I compute the expansion for 37? It is an odd number, so the final
bit must be 1; the rest of the expansion will be the same as the expansion of 18.
How can I compute the expansion of 18? 18 is even, so its final bit is 0, and
the rest of the expansion is the same as the expansion of 9. What is the binary
expansion for 9? 9 is odd, so its final bit is 1, and the rest of its binary expansion is
1
![](https://csdnimg.cn/release/download_crawler_static/6434161/bg14.jpg)
2 Recursion and Callbacks
the same as the binary expansion of 4. We can continue in this way, until finally
we ask about the binary expansion of 1, which of course is 1.
This procedure will work for any number. To compute the binary expansion
of a number n we proceed as follows:
1. If n is 1, its binary expansion is 1, and we may ignorethe rest of the procedure.
Similarly, if n is 0, the expansion is simply 0. Otherwise:
2. Compute k and b so that n = 2k + b and b = 0 or 1. To do this, simply
divide n by 2; k is the quotient, and b is the remainder, 0 if n was even, and
1ifn was odd.
3. Compute the binary expansion of k, using this same method. Call the
result E.
4. The binary expansion for n is Eb.
Let’s build a function called
binary() that calculates the expansion. Here is the
preamble, and step 1:
sub binary {
CODE LIBRARY
binary
my ($n) = @_;
return $n if $n == 0 || $n == 1;
Here is step 2:
my $k = int($n/2);
my$b=$n%2;
For the third step, we need to compute the binary expansion of k. How can
we do that? It’s easy, because we have a handy function for computing binary
expansions, called
binary() — or we will once we’ve finished writing it. We’ll
call
binary() with k as its argument:
my $E = binary($k);
Now the final step is a string concatenation:
return $E . $b;
}
This works. For example, if you invoke binary(37), you get the string 100101.
剩余591页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
webonperl
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- AirKiss技术详解:无线传递信息与智能家居连接
- Hibernate主键生成策略详解
- 操作系统实验:位示图法管理磁盘空闲空间
- JSON详解:数据交换的主流格式
- Win7安装Ubuntu双系统详细指南
- FPGA内部结构与工作原理探索
- 信用评分模型解析:WOE、IV与ROC
- 使用LVS+Keepalived构建高可用负载均衡集群
- 微信小程序驱动餐饮与服装业创新转型:便捷管理与低成本优势
- 机器学习入门指南:从基础到进阶
- 解决Win7 IIS配置错误500.22与0x80070032
- SQL-DFS:优化HDFS小文件存储的解决方案
- Hadoop、Hbase、Spark环境部署与主机配置详解
- Kisso:加密会话Cookie实现的单点登录SSO
- OpenCV读取与拼接多幅图像教程
- QT实战:轻松生成与解析JSON数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)