Programming Perl
Total Page:16
File Type:pdf, Size:1020Kb
Programming Perl #!/usr/bin/perl −w use strict; $_=’ev al("seek\040D ATA,0, 0;");foreach(1..2) {<DATA>;}my @camel1hump;my$camel; my$Camel ;while( <DATA>){$_=sprintf("%−6 9s",$_);my@dromedary 1=split(//);if(defined($ _=<DATA>)){@camel1hum p=split(//);}while(@dromeda ry1){my$camel1hump=0 ;my$CAMEL=3;if(defined($_=shif t(@dromedary1 ))&&/\S/){$camel1hump+=1<<$CAMEL;} $CAMEL−−;if(d efined($_=shift(@dromedary1))&&/\S/){ $camel1hump+=1 <<$CAMEL;}$CAMEL−−;if(defined($_=shift( @camel1hump))&&/\S/){$camel1hump+=1<<$CAMEL;}$CAMEL−−;if( defined($_=shift(@camel1hump))&&/\S/){$camel1hump+=1<<$CAME L;;}$camel.=(split(//,"\040..m‘{/J\047\134}L^7FX"))[$camel1h ump];}$camel.="\n";}@camel1hump=split(/\n/,$camel);foreach(@ camel1hump){chomp;$Camel=$_;tr/LJF7\173\175‘\047/\061\062\063 45678/;tr/12345678/JL7F\175\173\047‘/;$_=reverse;print"$_\040 $Camel\n";}foreach(@camel1hump){chomp;$Camel=$_;y/LJF7\173\17 5‘\047/12345678/;tr/12345678/JL7F\175\173\047‘/;$_=reverse;p rint"\040$_$Camel\n";}#japh−Erudil’;;s;\s*;;g;;eval; eval ("seek\040DATA,0,0;");undef$/;$_=<DATA>;s$\s*$$g;( );;s ;^.*_;;;map{eval"print\"$_\"";}/.{4}/g; __DATA__ \124 \1 50\145\040\165\163\145\040\157\1 46\040\1 41\0 40\143\141 \155\145\1 54\040\1 51\155\ 141 \147\145\0 40\151\156 \040\141 \163\16 3\ 157\143\ 151\141\16 4\151\1 57\156 \040\167 \151\164\1 50\040\ 120\1 45\162\ 154\040\15 1\163\ 040\14 1\040\1 64\162\1 41\144 \145\ 155\14 1\162\ 153\04 0\157 \146\ 040\11 7\047\ 122\1 45\15 1\154\1 54\171 \040 \046\ 012\101\16 3\16 3\15 7\143\15 1\14 1\16 4\145\163 \054 \040 \111\156\14 3\056 \040\ 125\163\145\14 4\040\ 167\1 51\164\1 50\0 40\160\ 145\162 \155\151 \163\163 \151\1 57\156\056 Kirrily Robert Paul Fenwick Jacinta Richardson Programming Perl by Kirrily Robert, Paul Fenwick, and Jacinta Richardson Copyright © 1999-2000 Netizen Pty Ltd Copyright © 2000 Kirrily Robert Copyright © 2001 Obsidian Consulting Group Pty Ltd Copyright © 2001-2011 Paul Fenwick ([email protected]) Copyright © 2001-2011 Jacinta Richardson ([email protected]) Copyright © 2001-2011 Perl Training Australia Open Publications License 1.0 Cover artwork Copyright (c) 2000 by Stephen B. Jenkins. Used with permission. The use of a camel image with the topic of Perl is a trademark of O’Reilly & Associates, Inc. Used with permission. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). Distribution of this work or derivative of this work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder. This document is a revised and edited copy of the Introduction to Perl and Intermediate Perl training notes originally created by Kirrily Robert and Netizen Pty Ltd. These revisions were made by Paul Fenwick and Jacinta Richardson. Copies of the original training manuals can be found at http://sourceforge.net/projects/spork This training manual is maintained by Perl Training Australia, and can be found at http://www.perltraining.com.au/notes.html This is version 1.39 of Perl Training Australia’s "Programming Perl" training manual. Table of Contents 1. About Perl Training Australia....................................................................................................... 1 Training....................................................................................................................................... 1 Consulting ................................................................................................................................... 1 Contact us.................................................................................................................................... 1 2. Introduction..................................................................................................................................... 3 Credits ......................................................................................................................................... 3 Course outline ............................................................................................................................. 3 Day 1 ................................................................................................................................. 3 Day 2 ................................................................................................................................. 3 Day 3 ................................................................................................................................. 3 Day 4 ................................................................................................................................. 3 Day 5 ................................................................................................................................. 4 Assumed knowledge ................................................................................................................... 4 Platform and version details........................................................................................................ 4 The course notes.......................................................................................................................... 4 Other materials............................................................................................................................ 5 3. What is Perl ..................................................................................................................................... 7 In this chapter.............................................................................................................................. 7 License ........................................................................................................................................ 7 Perl’s name and history............................................................................................................... 7 Typical uses of Perl ..................................................................................................................... 7 Text processing.................................................................................................................. 7 System administration tasks .............................................................................................. 7 CGI and web programming............................................................................................... 8 Database interaction .......................................................................................................... 8 Other Internet programming.............................................................................................. 8 Less typical uses of Perl .................................................................................................... 8 What is Perl like? ........................................................................................................................ 8 The Perl Philosophy.................................................................................................................... 9 There’s more than one way to do it ................................................................................... 9 A correct Perl program...................................................................................................... 9 Three virtues of a programmer.......................................................................................... 9 Laziness.................................................................................................................... 9 Impatience................................................................................................................ 9 Hubris.....................................................................................................................10 Three more virtues...........................................................................................................10 Share and enjoy!..............................................................................................................10 Parts of Perl...............................................................................................................................10 The Perl interpreter..........................................................................................................10 Manuals/Documentation..................................................................................................11 Perl Modules....................................................................................................................11 Chapter summary ......................................................................................................................11 4. A brief guide to perldoc................................................................................................................13 Using perldoc ............................................................................................................................13 Other ways to access perldoc ..........................................................................................13 Exercise ...........................................................................................................................13 Language features and tutorials ................................................................................................13 Looking