作者:Mark Jason Dominus
出版社:其它
页数:582
ISBN:ISBN 1558607013, 9781558607019
文件格式:PDF
Higher-Order Perl is about functional programmingtechniques in Perl. It’s about how to write functions that can modifyand manufacture other functions.
It’s difficult to explain briefly exactly what this means—it’s as if
someone was writing a book about object-oriented programming in 1982
when hardly anyone had heard of object-oriented programming.
Obviously, functional programming isn’t simply programming with
functions, because everyone does that already. Perhaps the best summary is
that it’s about writing functions that can manufacture other
functions.–>
Why would you want to do that? Because that way your code ismore flexible and more reusable. Instead of writing ten similarfunctions, you write a general pattern or framework that can generatethe functions you want; then you generate just the functions you needaccording to the pattern. The program doesn’t need to know in advancewhich functions are necessary; it can generate them as needed. Insteadof writing the complete program yourself, you get the computer to writeit for you.
HOP is full of useful and interesting examples that Perl programmerswill want to see. Chapter 1 is about writing recursive functions towalk the file system and to process recursively-structured data such asHTML documents. Chapter 2 discusses dispatch tables in the context ofreading configuration files. Chapter 4 concludes with an improvedreplacement for the WWW::SimpleRobot module, with better functionalityin one-third the code, and also contains a basic database query systemthat searches an HTTP log file backwards, delivering the most recentrecords first. Chapter 6 discusses the frequently asked question of howto generate a list of all the strings that will match a given regex andprovides an astonishingly simple solution. Later on, in Chapter 8, Ishow how to build a parser for regexes and attach it to the stringgenerator. Chapter 9 presents linogram, a complete constraint-baseddiagram-drawing system.