WROX - ISBN 1861003145 - Beginning Perl - Worldcolleges.info

1y ago
12 Views
2 Downloads
3.94 MB
672 Pages
Last View : 4d ago
Last Download : 3m ago
Upload by : Amalia Wilborn
Transcription

Beginning PerlSimon CozensWithPeter WainwrightWrox Press Ltd.

Beginning Perl 2000 Wrox PressAll rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmittedin any form or by any means, without the prior written permission of the publisher, except in the case ofbrief quotations embodied in critical articles or reviews.The authors and publisher have made every effort in the preparation of this book to ensure the accuracyof the information. However, the information contained in this book is sold without warranty, eitherexpress or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable forany damages caused or alleged to be caused either directly or indirectly by this book.First PublishedJune 2000Published by Wrox Press LtdArden House, 1102 Warwick Road, Acock's Green, Birmingham B27 6BH, UKPrinted in USAISBN 1-861003-14-5

Trademark AcknowledgementsWrox has endeavored to provide trademark information about all the companies and productsmentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee theaccuracy of this information.CreditsAuthorSimon CozensCategory ManagerViv EmeryContributing AuthorsPeter WainwrightAuthor AgentRob MillerAdditional MaterialJoshua SchachterProofreaderCarol PinchefskyTechnical ArchitectDaniel MaharryProduction ManagerLaurent LafonTechnical EditorsDan SquierDavid MercerProject AdministratorsMarsha CollinsNicola PhillipsTechnical ReviewersMatt BusiginYoz GrahameJerry HeymanDavid HudsonMatthew KirkwoodNick PerryWill PowellKirrily RobertsAdam TuroffBruce VarneyPaul WarrenProduction CoordinatorMark BurdettIlustrationsWilliam FallonCoverShelley FrazierIndexMartin Brooks

About the AuthorsSimon CozensSimon Cozens has been programming PCs as a freelance contractor since the age of 10. He wasintroduced to Perl and Linux little over three years ago and has been using both exclusively ever since.He is regularly contracted by Oracle Corporation to develop Perl scripts, including low-administrationweb server systems and tools to automate administration of Oracle databases, web servers and UNIXsystems.He has a special interest in documentation and literate programming, and has written a literateprogramming environment for Perl. His other Perl programs include a set of networking tools, aprogram to trap unsolicited email, and a series of varied Perl modules. He is currently working on asystem to read English descriptions of markup languages and generate translators between them, andalso a Perl version of the TeX typesetting utility.Simon lives in Oxford, where he investigates computer processing of Japanese. His interests includemusic, typesetting and the modern Greek language and culture.This book, like its author, isFor Evangelia Derou.Peter WainwrightPeter Wainwright is a software consultant and developer, living in London. He gained most of his earlyprogramming experience on Solaris, writing C applications. He then discovered Linux, shortly followedby Perl and Apache, and has been programming happily there ever since.When he is not developing software or writing professionally, he spends much of his free time pursuing hisinterest in space tourism and maintaining the ever-growing Space Future website at www.spacefuture.com,which is based on a Linux server running Apache, naturally. Someday, he hopes he'll get the time toactually implement some of the stuff he writes about.

This work is licensed under the Creative Commons Attribution-NoDerivs-NonCommercial License. To view a copy of thislicense, visit http://creativecommons.org/licenses/by-nd-nc/1.0 or send a letter to Creative Commons, 559 Nathan Abbott Way,Stanford, California 94305, USA.The key terms of this license are:Attribution: The licensor permits others to copy, distribute, display, and perform the work. In return, licensees must give theoriginal author credit.No Derivative Works: The licensor permits others to copy, distribute, display and perform only unaltered copies of the work -not derivative works based on it.Noncommercial: The licensor permits others to copy, distribute, display, and perform the work. In return, licensees may notuse the work for commercial purposes -- unless they get the licensor's permission.

Summary of ContentsIntroduction1Chapter 1: First Steps In Perl19Chapter 2: Working with Simple Values37Chapter 3: Lists and Hashes75Chapter 4: Loops and Decisions113Chapter 5: Regular Expressions147Chapter 6: Files and Data179Chapter 7: References217Chapter 8: Subroutines243Chapter 9: Running and Debugging Perl279Chapter 10: Modules309Chapter 11: Object-Oriented Perl335Chapter 12: Introduction to CGI377Chapter 13: Perl and Databases433Chapter 14: The World of Perl487Appendix A: Regular Expressions523Appendix B: Special Variables531Appendix C: Function Reference539Appendix D: The Perl Standard Modules567Appendix E: Command Line Reference579Appendix F: The ASCII Character Set585Appendix G: Licenses593Appendix H: Solutions to Exercises603Appendix J: Support, Errata and P2P.Wrox.Com623Index631

Table of ContentsIntroduction1A Potted History1Why Perl?2It's FreeWhat Is Perl Used For?Windows, UNIX, and Other Operating SystemsThe PromptWhat Do I Need To Use This Book?How Do I Get Perl?How To Get HelpPerl ResourcesConventionsDownloading the Source CodeExercisesErrataCustomer SupportChapter 1: First Steps In PerlProgramming Languages334456101315161617171919Interpreted vs. Compiled Source CodeLibraries, Modules and Packages2021Why is Perl Such A Great Language?22It's Really EasyFlexibility Is Our WatchwordPerl on the WebThe Open Source EffortDevelopers Releases and Topaz2222222323

Table of ContentsOur First Perl ProgramProgram StructureDocumenting Your ProgramsKeywordsStatements and Statement Blocks28282929ASCII and Unicode31Escape SequencesWhite Space3232Number Systems33The Perl Debugger34Summary34Exercises35Chapter 2: Working with Simple ValuesTypes of DataNumbersBinary, Hexadecimal and Octal NumbersStringsSingle- vs Double-quoted stringsAlternative DelimitersHere-DocumentsConverting between Numbers and StringsOperatorsNumeric OperatorsArithmetic OperatorsBitwise OperatorsTruth and FalsehoodBoolean OperatorsString OperatorsString ComparisonOperators To Be Seen LaterOperator PrecedenceVariablesModifying A VariableOperating and Assigning at OnceAutoincrement and AutodecrementMultiple 9596061626364

Table of ContentsScopingHow It WorksVariable Names656667Variable Interpolation68Currency Converter69Introducing STDIN 70Summary71Exercises72Chapter 3: Lists and HashesListsSimple ListsLess Simple ListsAccessing List ValuesList SlicesRangesCombining Ranges and SlicesArraysAssigning ArraysScalar vs List ContextAdding to an ArrayAccessing an ArrayAccessing Single ElementsAccessing Multiple ElementsRunning Through ArraysArray FunctionsHashesCreating a HashWorking with Hash ValuesAdding, Changing and Taking Values Away from a Accessing Multiple Values108SummaryExercises110111Chapter 4: Loops and DecisionsDeciding If.Logical Operators RevisitedComparing Numbers113114119120iii

Table of ContentsComparing StringsOther TestsLogical ConjunctionsRunning Unless.Statement ModifiersUsing LogicMultiple Choiceif elsif elseMore Elegant Solutions1, 2, Skip A Few, 99, 100for LoopsChoosing an IteratorWhat We Can Loop OverAliases and ValuesStatement ModifiersLooping While.while ( STDIN )Infinite LoopsRunning at Least OnceStatement ModifyingLooping UntilControlling Loop FlowBreaking OutGoing onto the ter 5: Regular ExpressionsWhat Are They?PatternsInterpolationEscaping Special CharactersAnchorsShortcuts and OptionsPosix and Unicode ClassesAlternativesRepetitionSummary TableBackreferencesHow the Engine 62163

Table of ContentsWorking with RegExpsSubstitutionChanging DelimitersModifiersSplitJoinTransliterationCommon BlundersMore Advanced TopicsInline CommentsInline ModifiersGrouping without BackreferencesLookaheads and LookbehindsBackreferences ummary176Exercises177Chapter 6: Files and DataFilehandles179179Reading LinesCreating FiltersReading More Than One LineWhat's My Line (Separator)?181183185186Reading Paragraphs at a TimeReading Entire Files188189Writing To FilesOpening a File for WritingWriting on a FilehandleAccessing FilehandlesWriting Binary DataSelecting a s200Opening Pipes201Piping InPiping OutFile Tests202205207v

Table of ContentsDirectoriesGlobbingReading Directories212212213Summary214Exercises215Chapter 7: References217What Is a Reference?217AnonymityThe Lifecycle of a ReferenceReference CreationAnonymous ReferencesUsing ReferencesArray Elements218218220222224Reference Modification225Hash ReferencesNotation Shorthands226227Reference Counting and Destruction230Counting Anonymous References231Using References for Complex Data StructuresMatricesAutovivificationTreesLinked Lists231231232236239Summary240Exercises241Chapter 8: SubroutinesThe 'Difference' Between Functions and SubroutinesUsuallyIn PerlUnderstanding SubroutinesDefining a SubroutineOrder of Declarationvi218243244244244245245247

Table of ContentsSubroutines for CalculationParameters and ArgumentsReturn ValuesThe return StatementCaching249249250252252ContextSubroutine Prototypes253254Understanding Scope255Global VariablesLexical Variables255258Runtime ScopeWhen to Use my() And When to Use local258260Passing More Complex Parameters260@ Provides Aliases!Lists Always CollapsePassing References to a SubroutinePassing Arrays and Hashes to a SubroutinePassing Filehandles to a SubroutineDefault Parameter ValuesNamed ParametersReferences to SubroutinesDeclaring References to SubroutinesCalling a Subroutine ReferenceCallbacksArrays and Hashes of References to ursion268Style Point: Writing Big Programs275Summary276Exercises277Chapter 9: Running and Debugging PerlError MessagesSyntax Error ChecklistMissing SemicolonsMissing Open/Close BracketsRunaway StringMissing CommaBrackets around ConditionsBarewords279280281281281282283283283vii

Table of ContentsDiagnostic ModuleswarningsstrictdiagnosticsPerl Command Line Switches-e-n and -p-c-i-M-s-I and @INC-a and -F-l and –0-TDebugging TechniquesBefore the Debugger.Debugging PrintsPare It DownContextScopePrecedenceDefensive ProgrammingStrategyCheck Your Return ValuesBe Prepared for the ImpossibleNever Trust the UserDefinedness and ExistenceHave Truthful, Helpful CommentsKeep the Code ry305Exercises305Chapter 10: ModulesTypes of Moduleviii309309

Table of ContentsWhy Do I Need Them?Including Other FilesdorequireuseChanging @INC310310310311312312Package Hierarchies312Exporters313The Perl Standard pecBenchmarkWin32CPANInstalling Modules with PPMInstalling a Module ManuallyThe CPAN ModuleBundlesBundle::LWPBundle::libnetSubmitting Your Own Module to CPANSummaryChapter 11: Object-Oriented PerlWorking with ObjectsTurning Tasks into OO ProgramsAre Your Subroutines Tasks?Do You Need Persistence?Do You Need Sessions?Do You Need OO?Do You Want The User To Be Unaware Of The Object?Are You Still Unsure?Improving Your 5335336336336336336337337337337338338339339ix

Table of ctorsRolling Your Own345Bless You, My ReferenceStoring AttributesThe Constructor345347348Considering InheritanceProviding Attributes349349Creating MethodsDistinguishing Class and Object MethodsGet-Set MethodsClass AttributesPrivatizing Your MethodsUtility MethodsDeath of an ObjectOur Finished ClassInheritanceWhat is it?Adding New MethodsOverriding Summary374Exercises375Chapter 12: Introduction to CGIHow Do I Get It to Work?Setting Up CGI on UNIX377377377ApacheStarting and Stopping ApacheDocumentRoot and cgi-bin378378379Setting up Perl CGI on Windows379Internet Information ServerPersonal Web ServerUsing Windows Web ServersWriting CGI ScriptsBasic CGIPlain TextHTML Textx340340341341380380381381381382382

Table of ContentsThe CGI EnvironmentHTTP Commands384388The GET MethodThe POST Method388389Writing Interactive CGI ScriptsA Form-Based ExamplePassing Parameters with CGI.pmChecking the HTTP MethodDetermining the Execution EnvironmentGenerating HTML ProgrammaticallyThe Environment Dumper RewrittenGenerating the HTTP HeaderGenerating the Document HeaderProducing Human-Readable HTMLGenerating HTML FormsGenerating Self-Referential URLsUsing the Same Script to Generate and Process FormsSaving and Loading CGI StateRedirecting from a CGI ScriptRegenerating Pages with Server PushCookies and Session TrackingDebugging CGI ScriptsUsing CGI.pm to Debug Scripts from the Command LineCGI SecurityAn Example of an Insecure CGI ScriptExecuting External 411412415420421422422423Reading and Writing to External Programs425Taint CheckingAn Example of a More Secure CGI ScriptCGI WrappersA Simple Security Checklist426428429429SummaryChapter 13: Perl and DatabasesPerl and DBMWhich DBM Implementation to UseAccessing DBM DatabasesOpening a DBM DatabaseChecking the State of a DBM Database431433434434435435436xi

Table of ContentsCreating DBM DatabasesEmptying the Contents of a DBM DatabaseClosing a DBM DatabaseAdding and Modifying DBM EntriesReading DBM EntriesDeleting from a DBM DatabaseWriting Portable DBM Programs with the AnyDBM ModuleCopying from One DBM Format to AnotherComplex Data StorageMulti-Level DBM (MLDBM)Beyond Flat Files and DBMIntroducing Relational DatabasesIntroducing DBISo What Do We Need?Installing DBIWhat's Available443444445446449450450451452454Our DB of Choice - MySQL456Installing on WindowsInstalling on LinuxSetting up the Root AccountTesting Our MySQL ServerInstalling DBD::MySQLWhat's Available Again?457457459459459460First Steps - The Database CycleConnecting To A DatabaseConnecting To A Remote DatabaseConnecting With The EnvironmentThe Fourth Parameter – Connection FlagsDisconnecting From a DatabaseInteracting With The DatabaseCreating a TablePopulating a Table With InformationA Note on QuotingKeeping the Table up to DatePulling Values from the DatabaseWhere Do the Records Go?Fetching a Single ValueBinding ColumnsFetching All ResultsExtracting Column Information From StatementsRemoving Information From The 4465467470472474475478480480482482484485

Table of ContentsChapter 14: The World of PerlIPC and NetworkingRunning ProgramssystemProcesses and IPCSignalsTrapping SignalsFork, Wait and ExecNetworkingIP AddressesSockets and PortsDomain Name ServiceNetworking ClientsWriting ClientsIO::SocketBlocking and IO::SelectServers with IO::SocketGraphical InterfacesWidgetsPerl/TkPerl/GTK and Perl/GNOMEGladePerl/QtPerl Win32 ModulePerl MathBigInt and BigFloatPerl Data Language (PDL)Simple TrigonometryAdding Complex Number SupportSecurity and Cryptographycrypt – Password SecurityPublic Key CryptographyWorking With DataLDAPDifferent Types of Data - One Way to Present ItWorking on the WebLog FilesPerlScriptCommunicating with CUsing C from PerlEmbedding PerlThe End of the 13515518518519520520520520520521521xiii

Table of ContentsAppendix A: Regular Expressions523Appendix B: Special Variables531Appendix C: Function Reference539Appendix D: The Perl Standard Modules567Appendix E: Command Line Reference579Appendix F: The ASCII Character Set585Appendix G: Licenses593Appendix H: Solutions to Exercises603Appendix J: Support, Errata and P2P.Wrox.Com623Index631xiv

Table of Contentsxv

This work is licensed under the Creative Commons Attribution-NoDerivs-NonCommercial License. To view a copy of thislicense, visit http://creativecommons.org/licenses/by-nd-nc/1.0 or send a letter to Creative Commons, 559 Nathan Abbott Way,Stanford, California 94305, USA.The key terms of this license are:Attribution: The licensor permits others to copy, distribute, display, and perform the work. In return, licensees must give theoriginal author credit.No Derivative Works: The licensor permits others to copy, distribute, display and perform only unaltered copies of the work -not derivative works based on it.Noncommercial: The licensor permits others to copy, distribute, display, and perform the work. In return, licensees may notuse the work for commercial purposes -- unless they get the licensor's permission.

IntroductionA Potted HistoryPerl was originally written by Larry Wall while he was working at NASA's Jet Propulsion Labs. Larry isan Internet legend: Not only is he well-known for Perl, but as the author of the UNIX utilities rn, whichwas one of the original Usenet newsreaders, and patch, a tremendously useful utility that takes a list ofdifferences between two files and allows you to turn one into the other. The word 'patch' used for thisactivity is now widespread.Perl started life as a 'glue' language, for the use of Larry and his officemates, allowing one to 'stick'different tools together by converting between their various data formats. It pulled together the bestfeatures of several languages: the powerful regular expressions from sed (the UNIX stream editor), thepattern-scanning language awk, and a few other languages and utilities. The syntax was further made upout of C, Pascal, Basic, UNIX shell languages, English and maybe a few other things along the way.Version 1 of Perl hit the world on December 18, 1987, and the language has been steadily developingsince then, with contributions from innumerable people. Perl 2 expanded the regular expressionsupport, while Perl 3 allowed Perl to deal with binary data. Perl 4 was released so that the Camel Book(see the Resources section at the end of this chapter) could refer to a new version of Perl.Perl 5 has seen some rather drastic changes in syntax and some pretty fantastic extensions to thelanguage. Perl 5 is (more or less) backwardly compatible with previous versions of the language, but atthe same time, makes a lot of the old code obsolete. Perl 4 code may still run, but Perl 4 style isdefinitely frowned upon these days.At the time of writing, the current stable release of Perl is 5.6, which is what this book will detail. Thatsaid, the maintainers of Perl are very careful to ensure that old code will run, perhaps all the way backto Perl 1 – changes and features that break existing programs are evaluated extremely seriously.Everything you see here will continue to function in the future.I say 'maintainers' because Larry no longer looks after Perl by himself – there is a group of 'porters' whomaintain the language and produce new releases. The 'perl5-porters' mailing list is the maindevelopment list for the language, and you can see the discussions archived orters/. For each release, one of the porters will carrythe 'patch pumpkin' – the responsibility for putting together and releasing the next version of Perl.

IntroductionWhere is Perl going in the future? Well, we expect Perl to develop steadily up the 5.x release series,adding more useful features and steadily deprecating more and more of the accumulated oldfashionedness, making it harder for people to justify the myth that Perl 4 is still alive and well.There is at least one existing project to rewrite Perl from scratch: Chip Salzenberg is heading up a teamcalled the Topaz project, which aims to produce a faster, more efficient Perl. Topaz is being written inC , rather than C, but hopes to remain compatible with Perl 5. At the moment, the Topaz team isn'tplanning to add any new features to the language, but I'm sure that as the project gains momentum,more features will be added. You might sometimes hear Topaz referred to as Perl 6, but it'll only reallybecome Perl 6 if Larry likes it – the way things are going, Topaz won't be in common use for quite sometime yet, and I expect that Perl 6 will be the natural development of the current Perl.Why Perl?Just like the Basic programming language, the name 'Perl' isn't really an acronym. People like makingup acronyms though, and Larry has two favorite expansions. According to its creator, perl is thePractical Extraction and Report Language, or the Pathologically Eclectic Rubbish Lister. Either way, itdoesn't really matter. Perl is a language for doing what you want to do.The Perl motto is 'There's More Than One Way To Do It', emphasizing both the flexibility of Perl andthe fact that Perl is about getting the job done. We can say that one Perl program is faster, or moreidiomatic, or more efficient than another, but if both do the same thing, Perl isn't going to judge whichone is 'better'. It also means that you don't need to know every last little detail about the language inorder to do what you want with it. You'll probably be able to achieve a lot of the tasks you might wantto use Perl for after the first four or five chapters of this book.Perl has some very obvious strengths It's very easy to learn, and learning a little Perl can get you a long way. Perl was designed to be easy for humans to write, rather than easy for computers tounderstand. The syntax of the language is a lot more like a human language than the strict,rigid grammars and structures of other languages, so it doesn't impose a particular way ofthinking upon you. Perl is very portable; That means what it sounds like – you can pick up a Perl program andcarry it around between computers. Perl is available for a huge variety of operating systemsand computers, and properly written programs should run almost anywhere that Perl doeswithout any change. Perl talks text. It thinks about words and sentences, where other languages see the character ata time. It also thinks about files in terms of lines, not individual bytes. Its 'regular expressions'allow you to search for and transform text in innumerable ways with ease and speed. Perl is what is termed a 'high-level language'. Some languages like C concern you withunnecessary, 'low-level' details about the computer's operation: making sure you have enoughfree memory, making sure all parts of your program are set up properly before you try to usethem, and leaving you with strange and unfriendly errors if you don't do so. Perl cuts you freefrom all this.However, since Perl is so easy to learn and to use, especially for quick little administrative tasks, 'real'Perl users tend to write programs for small, specific jobs. In these cases, the code is meant to have ashort lifespan and is for the programmer's eyes only. The problem is, these programs2

Introductionmay live a little longer than the programmer expects and be seen by other eyes too. The result is acryptic one-liner that is incomprehensible to everyone but the original programmer. Because of theproliferation of these rather concise and confusing programs, Perl has developed a reputation for beingarcane and unintelligible – one that I hope we can dispel during the course of this book.This reputation is unfair. It's possible to write code that is tortuous and difficult to follow in anyprogramming language, and Perl was never meant to be difficult. In fact, Perl is one of the easiestlanguages to learn, especially given its scope and flexibility.Throughout this book you will learn how to avoid the stereotypical 'spaghetti code' and how to writeprograms that are both easy to write and easy to follow. Let's work to kill off this negative image.It's FreeLarry started (and indeed, continued) Perl with the strong belief that software should be free – freelyavailable, freely modifiable, and freely distributable. Perl is developed and maintained by the porters,who are volunteers from the Perl user community, all of whom strive to make Perl as good as possible.This has a few nice side effects – the porters are working for love, rather than merely because it's theirjob, so they're motivated solely by their desire to see a better Perl. It also means Perl will continue to befree to use and distribute.This doesn't mean that Perl is part of the GNU suite of utilities. The GNU ("GNU's Not UNIX")project was set up to produce a freely usable, distributable, and modifiable version of the UNIXoperating system and its tools. It now produces a lot of helpful, free utilities. Perl is included indistributions of GNU software, but Perl itself is not a product of the Free Software Foundation, thebody that oversees GNU.While Perl can be distributed under the terms of the GNU Public License (which you can find athttp://www.gnu.org/), it can also be distributed under the Artistic License (found either with the perlsources or at http://www.opensource.org/licenses/), which purports to give more freedom to users andmore security to developers than the GPL. You may judge for yourself – we've included these licensesin Appendix G.Of course, those wanting to use Perl at work might be a little put off by this – managers like to paymoney for things and have pieces of paper saying that they can get irate at someone if it all stopsworking. There's a question in the Perl FAQ (Frequently Asked Questions) about how to get acommercial version or support for Perl, and we'll see how you can find out the answer for yourselfpretty soon.What Is Perl Used For?Far and away the most popular use of Perl is for CGI programming – that is, dynamically generatingweb pages. A whole chapter is devoted to introducing CGI programming in Perl. Perl is the powerbehind some of the most popular sites on the web: Slashdot (http://www.slashdot.org/), Amazon(http://www.amazon.com/), and Deja (http://www.deja.com/), and many others besides are almostentirely Perl-driven. We'll also look at some of the more recent extensions to the Perl/CGI concept:PerlScript, mod perl and HTML::Mason, which are becoming widely used.3

IntroductionOf course Perl is still widely used for its original purpose: extracting data from one source andtranslating it to another format. This covers everything from processing and summarizing system logs,through manipulating databases, reformatting text files, and simple search-and-replace operations, tosomething like alien, a program to port Linux software packages between different distributors'packaging formats. Perl even manages the data from the Human Genome Project, a task requiringmassive amounts of data manipulation.For system administrators, Perl is certainly the 'Swiss Army chainsaw' that it claims to be. It's great forautomating administration tasks, sending automatically generated mails and generally tidying up thesystem. It can process logs, report information on disk usage, produce reports on resource use andwatch for security problems. There are also extensions that allow Perl to deal with the Windows registryand run as a Windows NT service, not to mention functions built into that allow it to manipulate UNIXpasswd and group file entries.However, as you might expect, that's not all. Perl is becoming the de facto programming language of theInternet its networking capabilities have allowed it to be used to create clients, servers, and proxies forthings such as IRC, WWW, FTP, and practically every other protocol you wish to think of. It's used tofilter mail, automatically post news articles, mirror web sites, automate downloading and uploading, andso on. In fact, it's hard to find an area of the Internet in which Perl isn't used.Windows, UNIX, and Other Operating SystemsPerl is one of the most portable, if not the most portable programming languages around. It can becompiled on over 70 operating systems, and you can get binary distributions for most commonplatforms. Over the course of the book, we'll be looking at programs that can run equally well on almostany operating system.When we're setting up Perl and running our examples, we'll concentrate particularly on UNIX andWindows. By UNIX, I mean any commercial or free UNIX-like implementation – Solaris, Linux, Net-,Free- and OpenBSD, HP/UX, A/IX, and so on. Perl's home platform is UNIX, and 90% of the worlduses Windows. That said, the Perl language is the same for everyone. If you need help with yourparticular platform, you will probably be able to find a README file for it in the Perl sourcedistribution. We'll see how to get hold of that in the next chapter.While we're talking about operating system specifics, we'll use the filename extension .plx for ourexamples. Traditionally, UNIX programs take no extension, and Windows files take a three-letterextension to indicate their type. .plx is used by ActiveState to indicate a Perl program. Since UNIXisn't fussy, we'll use that idiom. You may also see the extension .pl in use for Perl programs (and, infact, I use it myself from time to time to remind me that a given program is in fact a Perl one), but to bereally pedantic, that's more properly used for Perl 4 libraries. These have, for the most part, beenreplaced by Perl 5 modules, which generally have the extension .pm. To avoid confusion, we won't usethe .pl extension.You can also get more information on portable Perl programming from the perlport documentation.Again, we'll see how to access this documentation very soon.4

IntroductionThe PromptIf you're primarily using your computer in a graphical environment like Windows or X, you may not befamiliar with using the command line interface, or 'shell'. Before these graphical environmen

programming environment for Perl. His other Perl programs include a set of networking tools, a program to trap unsolicited email, and a series of varied Perl modules. He is currently working on a system to read English descriptions of markup languages and generate translators between them, and also a Perl version of the TeX typesetting utility.

Related Documents:

Why Perl? Perl is built around regular expressions -REs are good for string processing -Therefore Perl is a good scripting language -Perl is especially popular for CGI scripts Perl makes full use of the power of UNIX Short Perl programs can be very short -"Perl is designed to make the easy jobs easy,

Perl can be embedded into web servers to speed up processing by as much as 2000%. Perl's mod_perl allows the Apache web server to embed a Perl interpreter. Perl's DBI package makes web-database integration easy. Perl is Interpreted Perl is an interpreted language, which means that your code can be run as is, without a

Other Perl resources from O’Reilly Related titles Learning Perl Programming Perl Advanced Perl Programming Perl Best Practices Perl Testing: A Developer’s . Intermedi

Run Perl Script Option 3: Create a Perl script my_script.pl: Run my_script.pl by calling perl: 8/31/2017 Introduction to Perl Basics I 10 print Hello World!\n; perl ./my_script.pl Option 4: For a small script with several lines, you can run it directly on the command line: perl -e print Hello World!\n;

Perl's creator, Larry Wall, announced it the next day in his State of the Onion address. Most notably, he said "Perl 6 is going to be designed by the community." Everyone thought that Perl 6 would be the version after the just-released Perl v5.6. That didn't happen, but that's why "Perl" was in the name "Perl 6."

tutorial Sorry about that but I have to keep my tutorial's example scripts short and to the point Finally, this is a tutorial for Perl/Tk only I will not be teaching perl here So if you know perl, continue But if you are a beginner to perl, I would recommend that you read my perl tutorial

Run Perl Script Option 3: Create a Perl script my_script.pl: Run my_script.pl by calling perl: 8/31/2017 Introduction to Perl Basics I 10 print Hello World!\n; perl ./my_script.pl Option 4: For a small script with several lines, you can run it directly on the command line: perl -e print Hello World!\n;

A Pre-Revolution Time Line Directions: Using the list in the box, fill in the events and laws that led up to the American Revolution. Write the event or law below each year. You may need to do some online research to complete this exercise. Boston Tea Party, Stamp Act Congress, Intolerable Acts, The French and Indian