Perl cookbook

1.1K 3.3K 0
Perl cookbook

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

;-_=_Scrolldown to the Underground_=_-; Perl Cookbook http://kickme.to/tiger/ By Tom Christiansen & Nathan Torkington; ISBN 1-56592-243-3, 794 pages First Edition, August 1998 (See the catalog page for this book.) Search the text of Perl Cookbook Index Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Table of Contents Foreword Preface Chapter 1: Strings Chapter 2: Numbers Chapter 3: Dates and Times Chapter 4: Arrays Chapter 5: Hashes Chapter 6: Pattern Matching Chapter 7: File Access Chapter 8: File Contents Chapter 9: Directories Chapter 10: Subroutines Chapter 11: References and Records Chapter 12: Packages, Libraries, and Modules Chapter 13: Classes, Objects, and Ties Chapter 14: Database Access Chapter 15: User Interfaces Chapter 16: Process Management and Communication Chapter 17: Sockets Chapter 18: Internet Services Chapter 19: CGI Programming Chapter 20: Web Automation The Perl CD Bookshelf Navigation Copyright © 1999 O'Reilly & Associates All Rights Reserved Foreword Next: Preface Foreword They say that it's easy to get trapped by a metaphor But some metaphors are so magnificent that you don't mind getting trapped in them Perhaps the cooking metaphor is one such, at least in this case The only problem I have with it is a personal one - I feel a bit like Betty Crocker's mother The work in question is so monumental that anything I could say here would be either redundant or irrelevant However, that never stopped me before Cooking is perhaps the humblest of the arts; but to me humility is a strength, not a weakness Great artists have always had to serve their artistic medium - great cooks just so literally And the more humble the medium, the more humble the artist must be in order to lift the medium beyond the mundane Food and language are both humble media, consisting as they of an overwhelming profusion of seemingly unrelated and unruly ingredients And yet, in the hands of someone with a bit of creativity and discipline, things like potatoes, pasta, and Perl are the basis of works of art that "hit the spot" in a most satisfying way, not merely getting the job done, but doing so in a way that makes your journey through life a little more pleasant Cooking is also one of the oldest of the arts Some modern artists would have you believe that so-called ephemeral art is a recent invention, but cooking has always been an ephemeral art We can try to preserve our art, make it last a little longer, but even the food we bury with our pharoahs gets dug up eventually So too, much of our Perl programming is ephemeral This aspect of Perl cuisine has been much maligned You can call it quick-and-dirty if you like, but there are billions of dollars out there riding on the supposition that fast food is not necessarily dirty food (We hope.) Easy things should be easy, and hard things should be possible For every fast-food recipe, there are countless slow-food recipes One of the advantages of living in California is that I have ready access to almost every national cuisine ever invented But even within a given culture, There's More Than One Way To Do It It's said in Russia that there are more recipes for borscht than there are cooks, and I believe it My mom's recipe doesn't even have any beets in it! But that's okay, and it's more than okay Borscht is a cultural differentiator, and different cultures are interesting, and educational, and useful, and exciting So you won't always find Tom and Nat doing things in this book the way I would them Sometimes they don't even things the same way as each other That's okay - again, this is a strength, not a weakness I have to confess that I learned quite a few things I didn't know before I read this book What's more, I'm quite confident that I still don't know it all And I hope I don't any time soon I often talk about Perl culture as if it were a single, static entity, but there are in fact many healthy Perl subcultures, not to mention sub-subcultures and supercultures and circumcultures in every conceivable combination, all inheriting attributes and methods from each other It can get confusing Hey, I'm confused most of the time So the essence of a cookbook like this is not to cook for you (it can't), or even to teach you how to cook (though it helps), but rather to pass on various bits of culture that have been found useful, and perhaps to filter out other bits of "culture" that grew in the refrigerator when no one was looking You in turn will pass on some of these ideas to other people, filtering them through your own experiences and tastes, your creativity and discipline You'll come up with your own recipes to pass to your children Just don't be surprised when they in turn cook up some recipes of their own, and ask you what you think Try not to make a face I commend to you these recipes, over which I've made very few faces - Larry Wall June, 1998 Perl Cookbook Book Index Next: Preface Preface [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Previous: Foreword Preface Next: Platform Notes Preface Contents: What's in This Book Platform Notes Other Books Conventions Used in This Book We'd Like to Hear from You Acknowledgments The investment group eyed the entrepreneur with caution, their expressions flickering from scepticism to intrigue and back again "Your bold plan holds promise," their spokesman conceded "But it is very costly and entirely speculative Our mathematicians mistrust your figures Why should we entrust our money into your hands? What you know that we not?" "For one thing," he replied, "I know how to balance an egg on its point without outside support Do you?" And with that, the entrepreneur reached into his satchel and delicately withdrew a fresh hen's egg He handed over the egg to the financial tycoons, who passed it amongst themselves trying to carry out the simple task At last they gave up In exasperation they declared, "What you ask is impossible! No man can balance an egg on its point." So the entrepreneur took back the egg from the annoyed businessmen and placed it upon the fine oak table, holding it so that its point faced down Lightly but firmly, he pushed down on the egg with just enough force to crush in its bottom about half an inch When he took his hand away, the egg stood there on its own, somewhat messy, but definitely balanced "Was that impossible?" he asked "It's just a trick," cried the businessmen "Once you know how, anyone can it." "True enough," came the retort "But the same can be said for anything Before you know how, it seems an impossibility Once the way is revealed, it's so simple that you wonder why you never thought of it that way before Let me show you that easy way, so others may easily follow Will you trust me?" Eventually convinced that this entrepreneur might possibly have something to show them, the skeptical venture capitalists funded his project From the tiny Andalusian port of Palos de Moguer set forth the Niña, the Pinta, and the Santa María, led by an entrepreneur with a slightly broken egg and his own ideas: Christopher Columbus Many have since followed Approaching a programming problem can be like balancing Columbus's egg If no one shows you how, you may sit forever perplexed, watching the egg - and your program - fall over again and again, no closer to the Indies than when you began This is especially true in a language as idiomatic as Perl This book had its genesis in two chapters of the first edition of Programming Perl Chapters and covered "Common Tasks in Perl" and "Real Perl Programs." Those chapters were highly valued by readers because they showed real applications of the language - how to solve day-to-day tasks using Perl While revising the Camel, we realized that there was no way to proper justice to those chapters without publishing the new edition on onionskin paper or in multiple volumes The book you hold in your hands, published two years after the revised Camel, tries to proper justice to those chapters We trust it has been worth the wait This book isn't meant to be a complete reference book for Perl, although we describe some parts of Perl previously undocumented Having a copy of Programming Perl handy will allow you to look up the exact definition of an operator, keyword, or function Alternatively, every Perl installation comes with over 1,000 pages of searchable, online reference materials If those aren't where you can get at them, see your system administrator Neither is this book meant to be a bare-bones introduction for programmers who've never seen Perl before That's what Learning Perl, a kinder and gentler introduction to Perl, is designed for (If you're on a Microsoft system, you'll probably prefer the Learning Perl on Win32 Systems version.) Instead, this is a book for learning more Perl Neither a reference book nor a tutorial book, the Perl Cookbook serves as a companion book to both It's for people who already know the basics but are wondering how to mix all those ingredients together into a complete program Spread across 20 chapters and more than 300 focused topic areas affectionately called recipes, this book contains thousands of solutions to everyday challenges encountered by novice and journeyman alike We tried hard to make this book useful for both random and sequential access Each recipe is self-contained, but has a list of references at the end should you need further information on the topic We've tried to put the simpler, more common recipes toward the front of each chapter and the simpler chapters toward the front of the book Perl novices should find that these recipes about Perl's basic data types and operators are just what they're looking for We gradually work our way through topic areas and solutions more geared toward the journeyman Perl programmer Every now and then we include material that should inspire even the master Perl programmer Each chapter begins with an overview of that chapter's topic This introduction is followed by the main body of each chapter, its recipes In the spirit of the Perl slogan of TMTOWTDI, "There's more than one way to it," most recipes show several different techniques for solving the same or closely related problems These recipes range from short-but-sweet solutions to in-depth mini-tutorials Where more than one technique is given, we often show costs and benefits of each approach As with a traditional cookbook, we expect you to access this book more or less at random When you want to learn how to something, you'll look up its recipe Even if the exact solutions presented don't fit your problem exactly, they'll give you ideas about possible approaches Each chapter concludes with one or more complete programs Although some recipes already include small programs, these longer applications highlight the chapter's principal focus and combine techniques from other chapters, just as any real-world program would All are useful, and many are used on a daily basis Some even helped us put this book together What's in This Book The first quarter of the book addresses Perl's basic data types, spread over five chapters Chapter 1, Strings, covers matters like accessing substrings, expanding function calls in strings, and parsing comma-separated data Chapter 2, Numbers, tackles oddities of floating point representation, placing commas in numbers, and pseudo-random numbers Chapter 3, Dates and Times, demonstrates conversions between numeric and string date formats and using timers Chapter 4, Arrays, covers everything relating to list and array manipulation, including finding unique elements in a list, efficiently sorting lists, and randomizing them Chapter 5, Hashes, concludes the basics with a demonstration of the most useful data type, the associative array The chapter shows how to access a hash in insertion order, how to sort a hash by value, and how to have multiple values per key Chapter 6, Pattern Matching, is by far the largest chapter Recipes include converting a shell wildcard into a pattern, matching letters or words, matching multiple lines, avoiding greediness, and matching strings that are close to but not exactly what you're looking for Although this chapter is the longest in the book, it could easily have been longer still - every chapter contains uses of regular expressions It's part of what makes Perl Perl The next three chapters cover the filesystem Chapter 7, File Access, shows opening files, locking them for concurrent access, modifying them in place, and storing filehandles in variables Chapter 8, File Contents, discusses watching the end of a growing file, reading a particular line from a file, and random access binary I/O Finally, in Chapter 9, Directories, we show techniques to copy, move, or delete a file, manipulate a file's timestamps, and recursively process all files in a directory Chapters 10 through 13 focus on making your program flexible and powerful Chapter 10, Subroutines, includes recipes on creating persistent local variables, passing parameters by reference, calling functions indirectly, and handling exceptions Chapter 11, References and Records, is about data structures; basic manipulation of references to data and functions are demonstrated Later recipes show how to create record-like data structures and how to save and restore these structures from permanent storage Chapter 12, Packages, Libraries, and Modules, concerns breaking up your program into separate files; we discuss how to make variables and functions private to a module, replace built-ins, trap calls to missing modules, and use the h2ph and h2xs tools to interact with C and C++ code Lastly, Chapter 13, Classes, Objects, and Ties, covers the fundamentals of building your own object-based module to create user-defined types, complete with constructors, destructors, and inheritance Other recipes show examples of circular data structures, operator overloading, and tied data types The next two chapters are about interfaces: one to databases, the other to display devices Chapter 14, Database Access, includes techniques for manipulating indexed text files, locking DBM files and storing data in them, and a demonstration of Perl's SQL interface Chapter 15, User Interfaces, covers topics such as clearing the screen, processing command-line switches, single-character input, moving the cursor using termcap and curses, and platform independent graphical programming using Tk The last quarter of the book is devoted to interacting with other programs and services Chapter 16, Process Management and Communication, is about running other programs and collecting their output, handling zombie processes, named pipes, signal management, and sharing variables between running programs Chapter 17, Sockets, shows how to establish stream connections or use datagrams to create low-level networking applications for client-server programming Chapter 18, Internet Services, is about higher-level protocols such as mail, FTP, Usenet news, and Telnet Chapter 19, CGI Programming, contains recipes for processing web forms, trapping their errors, avoiding shell escapes for security, managing cookies, shopping cart techniques, and saving forms to files or pipes The final chapter of the book, Chapter 20, Web Automation, covers non-interactive uses of the Web Recipes include fetching a URL, automating form submissions in a script, extracting URLs from a web page, removing HTML tags, finding fresh or stale links, and processing server log files Previous: Foreword Foreword Perl Cookbook Next: Platform Notes Book Index Platform Notes [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Previous: What's in This Book Preface Next: Other Books Platform Notes This book was developed using Perl release 5.004_04 That means major release 5, minor release 4, and patch level We tested most programs and examples under BSD, Linux, and SunOS, but that doesn't mean they'll only work on those systems Perl was designed for platform independence When you use Perl as a general-purpose programming language, employing basic operations like variables, patterns, subroutines, and high-level I/O, your program should work the same everywhere that Perl runs - which is just about everywhere The first two thirds of this book uses Perl for general-purpose programming Perl was originally conceived as a high-level, cross-platform language for systems programming Although it has long since expanded beyond its original domain, Perl continues to be heavily used for systems programming, both on its native Unix systems and elsewhere Most recipes in Chapters 14 through 18 deal with classic systems programming For maximum portability in this area, we've mainly focused on open systems as defined by POSIX, the Portable Operating System Interface, which includes nearly every form of Unix and numerous other systems as well Most recipes should run with little or no modification on any POSIX system You can still use Perl for systems programming work even on non-POSIX systems by using vendor-specific modules, but these are not covered in this book That's because they're not portable - and to be perfectly honest, because the authors have no such systems at their disposal Consult the documentation that came with your port of Perl for any proprietary modules that may have been included But don't worry Many recipes for systems programming should work on non-POSIX systems as well, especially those dealing with databases, networking, and web interaction That's because the modules used for those areas hide platform dependencies The principal exception is those few recipes and programs that rely upon multitasking constructs, notably the powerful fork function, standard on POSIX systems, but few others When we needed structured files, we picked the convenient Unix /etc/passwd database; when we needed a text file to read, we picked /etc/motd ; and when we needed a program to produce output, we picked who (1) These were merely chosen to illustrate the principles - the principles work whether or not your system has these files and programs Previous: What's in This Book Perl Cookbook Next: Other Books Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: T -t option : 15.2 Testing Whether a Program Is Running Interactively tabs : (see whitespace) tags, HTML : (see HTML) tailwtmp program : 8.18 Program: tailwtmp taint mode : 19.4 Writing a Safe CGI Program tan( ) : 2.12 Calculating More Trigonometric Functions tcapdemo program (example) : 15.18 Program: Small termcap program tcgrep program : 6.22 Program: tcgrep TCP protocol communicating over : 17.3 Communicating over TCP writing clients : 17.1 Writing a TCP Client writing servers : 17.2 Writing a TCP Server TCP_NODELAY socket option : 17.3 Communicating over TCP tctee program : 8.19 Program: tctee tear-off menus : 15.14 Creating Menus with Tk tell( ) : 8.0 Introduction telnet, simulating from programs : 18.6 Simulating Telnet from a Program template( ) : 20.9 Creating HTML Templates templates HTML : 20.9 Creating HTML Templates for modules : 12.18 Example: Module Template temporary files : 7.5 Creating Temporary Files modifying files with : 7.8 Modifying a File in Place with Temporary File modifying files without : 7.10 Modifying a File in Place Without a Temporary File Term::ANSIColor module : 15.5 Changing Text Color Term::Cap module 15.3 Clearing the Screen 15.18 Program: Small termcap program Term::ReadKey module : 1.12 Reformatting Paragraphs checking for waiting input : 15.9 Checking for Waiting Input determining window size : 15.4 Determining Terminal or Window Size reading from keyboard : 15.6 Reading from the Keyboard reading passwords : 15.10 Reading Passwords Term::ReadLine module : 15.11 Editing Input Term::ReadLine::Gnu module : 15.11 Editing Input terminal : (see user interfaces) termios interface : 15.8 Using POSIX termios text : (see strings) text color : 15.5 Changing Text Color Text::ParseWords module : 1.15 Parsing Comma-Separated Data Text::Soundex module : 1.16 Soundex Matching Text::Tabs module : 1.7 Expanding and Compressing Tabs Text::Template module : 20.9 Creating HTML Templates Text::Wrap module : 1.12 Reformatting Paragraphs threads : 16.17 Writing a Signal Handler tie( ) 13.15 Creating Magic Variables with tie 14.1 Making and Using a DBM File Tie::IxHash module : 5.6 Retrieving from a Hash in Insertion Order Tie::RefHash module : 5.12 Hashing References TIESCALAR( ), TIEARRAY( ), TIEHASH( ), TIEHANDLE( ) : 13.15 Creating Magic Variables with tie tildes in filenames : 7.3 Expanding Tildes in Filenames time : (see date and time) time( ) : 3.0 Introduction time zones : (see date and time) Time::gmtime module 3.0 Introduction 3.3 Converting Epoch Seconds to DMYHMS Time::HiRes module : 3.9 High-Resolution Timers Time::Local module 3.0 Introduction 3.2 Converting DMYHMS to Epoch Seconds Time::localtime module : 3.0 Introduction Time::timelocal module : 3.3 Converting Epoch Seconds to DMYHMS Time::tm module : 3.0 Introduction timegm( ) 3.0 Introduction 3.2 Converting DMYHMS to Epoch Seconds timelocal( ) 3.0 Introduction 3.2 Converting DMYHMS to Epoch Seconds timers, high-resolution : 3.9 High-Resolution Timers timestamps : 9.1 Getting and Setting Timestamps timing out operations : 16.21 Timing Out an Operation Tk toolkit : 15.0 Introduction dialog boxes : 15.15 Creating Dialog Boxes with Tk menus : 15.14 Creating Menus with Tk removing DOS shell window : 15.17 Removing the DOS Shell Window with Windows Perl/Tk resize events : 15.16 Responding to Tk Resize Events tkshufflepod program : 15.19 Program: tkshufflepod tksample3 program (example) : 15.15 Creating Dialog Boxes with Tk tksample4 program (example) : 15.15 Creating Dialog Boxes with Tk tkshufflepod program (example) : 15.19 Program: tkshufflepod tmpfile( ) (POSIX module) : 7.5 Creating Temporary Files tmpnam( ) (POSIX module) : 7.5 Creating Temporary Files today's date : 3.1 Finding Today's Date tr/// operator ~ operator with : 1.1 Accessing Substrings converting case with : 1.9 Controlling Case trailing growing files : 8.5 Trailing a Growing File trailing whitespace, removing : 1.14 Trimming Blanks from the Ends of a String transparently persistent data structures : 11.14 Transparently Persistent Data Structures trapping undefined function calls : 10.15 Trapping Undefined Function Calls with AUTOLOAD traversing hashes : 5.4 Traversing a Hash tree structures : 11.15 Program: Binary Trees tree, directory : (see directories) trigonometry : 2.11 Doing Trigonometry in Degrees, not Radians truncate( ) : 8.0 Introduction truth (Boolean) : 1.0 Introduction tsc_permute program (example) : 4.19 Program: permute tty devices, testing for : 15.2 Testing Whether a Program Is Running Interactively typed referents : 11.0 Introduction typeglobs 1.18 Program: psgrep 7.16 Storing Filehandles in Variables 7.20 Copying Filehandles 10.13 Saving Global Values Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: U \U string escape : 1.9 Controlling Case \u string escape : 1.9 Controlling Case uc( ) : 1.9 Controlling Case ucfirst( ) : 1.9 Controlling Case UDP protocol writing clients : 17.4 Setting Up a UDP Client writing servers : 17.5 Setting Up a UDP Server udpmsg program (example) : 17.5 Setting Up a UDP Server udpqotd program (example) : 17.5 Setting Up a UDP Server umask values : 7.1 Opening a File uname( ) (POSIX) : 17.8 Finding Your Own Name and Address unbuffered input/output 7.0 Introduction 7.12 Flushing Output 8.0 Introduction 15.6 Reading from the Keyboard uncontrol subroutine : 15.8 Using POSIX termios undef( ) : 11.0 Introduction undefined (undef) value : 1.0 Introduction Unicode : 1.0 Introduction unimport( ) 1.18 Program: psgrep 13.15 Creating Magic Variables with tie unions of lists : 4.7 Finding Elements in One Array but Not Another unique list elements, extracting : 4.6 Extracting Unique Elements from a List UNIVERSAL package : 13.8 Determining Subclass Membership Unix domain sockets 17.0 Introduction 17.6 Using UNIX Domain Sockets UnixDate( ) : 3.7 Parsing Dates and Times from Strings unlink( ) 9.2 Deleting a File 9.8 Removing a Directory and Its Contents unpack( ) 1.1 Accessing Substrings 1.4 Converting Between ASCII Characters and Values 8.15 Reading Fixed-Length Records converting binary and decimal numbers : 2.4 Converting Between Binary and Decimal unshift( ) circular lists : 4.16 Implementing a Circular List Tie::IxHash module and : 5.6 Retrieving from a Hash in Insertion Order untie( ) : 14.1 Making and Using a DBM File uppercase, converting to lowercase : 1.9 Controlling Case URI::Heuristic : 20.7 Finding Stale Links urlify program : 6.21 Program: urlify URLs (Uniform Resource Locators) : 19.0 Introduction extracting from HTML : 20.3 Extracting URLs fetching from Perl scripts : 20.1 Fetching a URL from a Perl Script putting HTML links around : 6.21 Program: urlify redirecting CGI requests : 19.8 Redirecting to a Different Location use pragmas : 12.0 Introduction trapping errors in : 12.2 Trapping Errors in require or use use autouse pragma : 12.3 Delaying use Until Run Time use lib pragma : 12.7 Keeping Your Own Module Directory use locale pragma 1.9 Controlling Case 6.0 Introduction 6.12 Honoring Locale Settings in Regular Expressions use overload pragma : 13.14 Overloading Operators Usenet news : 18.4 Reading and Posting Usenet News Messages user input : (see input) user interfaces : 15.0 Introduction checking for waiting input : 15.9 Checking for Waiting Input clearing the screen : 15.3 Clearing the Screen controlling programs with Expect : 15.13 Controlling Another Program with Expect determining window size : 15.4 Determining Terminal or Window Size dialog boxes with Tk : 15.15 Creating Dialog Boxes with Tk editing input : 15.11 Editing Input full-screen mode : 15.0 Introduction managing screen : 15.12 Managing the Screen manipulating terminal directly : 15.8 Using POSIX termios menus with Tk : 15.14 Creating Menus with Tk multiscreen CGI scripts : 19.12 Writing a Multiscreen CGI Script parsing command-line options : 15.1 Parsing Program Arguments reading from keyboard : 15.6 Reading from the Keyboard reading passwords without echo : 15.10 Reading Passwords removing DOS shell window : 15.17 Removing the DOS Shell Window with Windows Perl/Tk ringing terminal bell : 15.7 Ringing the Terminal Bell tcapdemo program : 15.18 Program: Small termcap program testing programs if running interactively : 15.2 Testing Whether a Program Is Running Interactively text color : 15.5 Changing Text Color Tk resize events : 15.16 Responding to Tk Resize Events userstats program (example) : 14.1 Making and Using a DBM File utime( ) : 9.1 Getting and Setting Timestamps uvi program (example) : 9.1 Getting and Setting Timestamps Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: V values (see also numbers; strings; variables) 1.2 Establishing a Default Value comma-separated (CSV) initializing arrays with : 4.1 Specifying a List In Your Program parsing : 1.15 Parsing Comma-Separated Data converting with ASCII characters : 1.4 Converting Between ASCII Characters and Values definedness 1.0 Introduction 1.2 Establishing a Default Value exchanging between scalar variables : 1.3 Exchanging Values Without Using Temporary Variables values( ), Tie::IxHash module and : 5.6 Retrieving from a Hash in Insertion Order variable-length text fields : 8.9 Processing Variable-Length Text Fields variables expanding in user input : 1.8 Expanding Variables in User Input filehandles as 7.0 Introduction 7.16 Storing Filehandles in Variables loop (iterator) variables : 4.4 Doing Something with Every Element in a List magic : 13.15 Creating Magic Variables with tie private for modules : 12.4 Making Variables Private to a Module private, for subroutines : 10.2 Making Variables Private to a Function scalars : (see scalars) sharing among different processes : 16.12 Sharing Variables in Different Processes strings : (see strings) vbsh program (example) : 15.11 Editing Input $VERSION variable (use pragma) : 12.1 Defining a Module's Interface VERSION( ) (UNIVERSAL) : 13.8 Determining Subclass Membership visual bell : 15.7 Ringing the Terminal Bell vrfy program (example) : 18.9 Program: expn and vrfy Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: W wait( ) : 16.19 Avoiding Zombie Processes waitpid( ) : 16.19 Avoiding Zombie Processes wantarray( ) : 10.6 Detecting Return Context WARN signal : 16.15 Installing a Signal Handler warn( ), dialog box for : 15.15 Creating Dialog Boxes with Tk warnings (see also errors) 12.12 Reporting Errors and Warnings Like Built-Ins reporting like built-ins : 12.12 Reporting Errors and Warnings Like Built-Ins wc program : 8.2 Counting Lines (or Paragraphs or Records) in a File web, references on : 19.0 Introduction web architecture : 19.0 Introduction web automation : 20.0 Introduction converting ASCII to/from HTML : 20.4 Converting ASCII to HTML extracting URLs from HTML : 20.3 Extracting URLs fetching URLs : 20.1 Fetching a URL from a Perl Script finding stale/fresh links : 20.7 Finding Stale Links HTML templates : 20.9 Creating HTML Templates HTML text substitutions : 20.14 Program: htmlsub mirroring web pages : 20.10 Mirroring Web Pages parsing web server log files : 20.12 Parsing a Web Server Log File processing server logs : 20.13 Processing Server Logs removing/extracting HTML tags : 20.6 Extracting or Removing HTML Tags robots : 20.11 Creating a Robot submitting HTML forms : 20.2 Automating Form Submission web server logs : 19.0 Introduction parsing : 20.12 Parsing a Web Server Log File processing : 20.13 Processing Server Logs week_number( ) : 3.6 Day in a Week/Month/Year or Week Number weekearly program (example) : 8.13 Updating a Random-Access File weeks : (see date and time) weighted_rand( ) (example) : 2.10 Generating Biased Random Numbers whitespace deleting leading/trailing : 1.14 Trimming Blanks from the Ends of a String extracting ranges of lines : 6.8 Extracting a Range of Lines indenting here documents : 1.11 Indenting Here Documents matching across multiple lines : 6.6 Matching Multiple Lines matching words : 6.3 Matching Words in pod documentation : 12.16 Documenting Your Module with Pod sorted text in columns and : 4.18 Program: words sorting du command output : 5.16 Program: dutree tabs, expanding/compressing : 1.7 Expanding and Compressing Tabs who.cgi script (example) : 19.11 Creating Sticky Widgets whoami( ) : 10.4 Determining Current Function Name whois service : 18.8 Using Whois to Retrieve Information from the InterNIC whowasi( ) : 10.4 Determining Current Function Name wildcards (shell) for regexp matching : 6.9 Matching Shell Globs as Regular Expressions Win32::Process module : 15.17 Removing the DOS Shell Window with Windows Perl/Tk window size, determining 12.14 Using h2ph to Translate C #include Files 15.4 Determining Terminal or Window Size windows dialog boxes (Tk) : 15.15 Creating Dialog Boxes with Tk DOS shell, removing : 15.17 Removing the DOS Shell Window with Windows Perl/Tk menu bars in (Tk) : 15.14 Creating Menus with Tk winsz program (example) : 12.14 Using h2ph to Translate C #include Files words duplicate, finding : 6.16 Detecting Duplicate Words fuzzy matching : 6.13 Approximate Matching matching abbreviations : 6.20 Matching Abbreviations pattern matching : 6.3 Matching Words pluralizing, based on numbers : 2.18 Printing Correct Plurals processing all in file : 8.3 Processing Every Word in a File reversing : 1.6 Reversing a String by Word or Character sorting into columns : 4.18 Program: words substitutions for specific : 1.17 Program: fixstyle text color, changing : 15.5 Changing Text Color wrapping paragraph text : 1.12 Reformatting Paragraphs words program (example) : 4.18 Program: words wrapdemo program (example) : 1.12 Reformatting Paragraphs wrapping paragraph text : 1.12 Reformatting Paragraphs write( ) : 16.4 Reading or Writing to Another Program writing files : (see file access; file contents) wtmp file, adding records to : 8.18 Program: tailwtmp Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: X x command (Perl debugger) : 11.11 Printing Data Structures x operator : 2.14 Multiplying Matrices -X operators : 9.0 Introduction /x substitution modifier : 1.8 Expanding Variables in User Input comments in regular expressions : 6.4 Commenting Regular Expressions XS interface 12.8 Preparing a Module for Distribution 12.15 Using h2xs to Make a Module with C Code Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: Y Year 2000 problem : 3.0 Introduction years : (see date and time) Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Index: Z zombies 16.0 Introduction 16.19 Avoiding Zombie Processes Search | Symbols | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z Copyright © 1999 O'Reilly & Associates, Inc All Rights Reserved [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook ] ... June, 1998 Perl Cookbook Book Index Next: Preface Preface [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl Cookbook. .. Foreword Perl Cookbook Next: Platform Notes Book Index Platform Notes [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl Programming | Perl. .. Book Perl Cookbook Next: Other Books What's in This Book Book Index Other Books [ Library Home | Perl in a Nutshell | Learning Perl | Learning Perl on Win32 | Programming Perl | Advanced Perl

Ngày đăng: 10/04/2017, 09:04

Từ khóa liên quan

Mục lục

  • Perl Cookbook

    • Table of Contents

    • Foreword

    • Preface

      • [Preface] Platform Notes

      • [Preface] Other Books

      • [Preface] Conventions Used in This Book

      • [Preface] We'd Like to Hear from You

      • [Preface] Acknowledgments

      • [Chapter 1] Strings

        • Recipe 1.1. Accessing Substrings

        • Recipe 1.2. Establishing a Default Value

        • Recipe 1.3. Exchanging Values Without Using Temporary Variables

        • Recipe 1.4. Converting Between ASCII Characters and Values

        • Recipe 1.5. Processing a String One Character at a Time

        • Recipe 1.6. Reversing a String by Word or Character

        • Recipe 1.7. Expanding and Compressing Tabs

        • Recipe 1.8. Expanding Variables in User Input

        • Recipe 1.9. Controlling Case

        • Recipe 1.10. Interpolating Functions and Expressions Within Strings

        • Recipe 1.11. Indenting Here Documents

        • Recipe 1.12. Reformatting Paragraphs

        • Recipe 1.13. Escaping Characters

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan