Tải bản đầy đủ

OReilly learning perl 4th edition jul 2005 ISBN 0596101058

LearningPerl,4thEdition
Bybriandfoy,TomPhoenix,RandalL.Schwartz
...............................................
Publisher:O'Reilly
PubDate:July2005
ISBN:0-596-10105-8
Pages:312

TableofContents|Index

LearningPerl,betterknownas"theLlamabook",startstheprogrammeronthewayto
mastery.WrittenbythreeprominentmembersofthePerlcommunitywhoeachhave
severalyearsofexperienceteachingPerlaroundtheworld,thislatesteditionhasbeen
updatedtoaccountforalltherecentchangestothelanguageuptoPerl5.8.
Perlisthelanguageforpeoplewhowanttogetworkdone.ItstartedasatoolforUNIX
systemadministratorswhoneededsomethingpowerfulforsmalltasks.Sincethen,Perl
hasblossomedintoafull-featuredprogramminglanguageusedforwebprogramming,
databasemanipulation,XMLprocessing,andsystemadministration--onpracticallyall
platforms--whileremainingthefavoritetoolforthesmalldailytasksitwasdesignedfor.
YoumightstartusingPerlbecauseyouneedit,butyou'llcontinuetouseitbecauseyou
loveit.

InformedbytheiryearsofsuccessatteachingPerlasconsultants,theauthorshavereengineeredtheLlamatobettermatchthepaceandscopeappropriateforreadersgetting
startedwithPerl,whileretainingthedetaileddiscussion,thoroughexamples,andeclectic
witforwhichtheLlamaisfamous.
Thebookincludesnewexercisesandsolutionssoyoucanpracticewhatyou'velearned
whileit'sstillfreshinyourmind.Herearejustsomeofthetopicscovered:
datastructures
minimalmatching
threading
dataparsing
references
objects
modules


packageimplementation

IfyouaskPerlprogrammerstodaywhatbooktheyreliedonmostwhentheywere
learningPerl,you'llfindthatanoverwhelmingmajoritywillpointtotheLlama.Withgood
reason.OtherbooksmayteachyoutoprograminPerl,butthisbookwillturnyouintoa
Perlprogrammer.


LearningPerl,4thEdition
Bybriandfoy,TomPhoenix,RandalL.Schwartz
...............................................
Publisher:O'Reilly
PubDate:July2005
ISBN:0-596-10105-8
Pages:312

TableofContents|Index

















































Copyright
Preface
HistoryofThisBook
TypographicalConventions
UsingCodeExamples
HowtoContactUs
SafariEnabled
Acknowledgments
Chapter1.Introduction
Section1.1.QuestionsandAnswers
Section1.2.WhatDoes"Perl"StandFor?
Section1.3.HowCanIGetPerl?
Section1.4.HowDoIMakeaPerlProgram?
Section1.5.AWhirlwindTourofPerl
Section1.6.Exercises
Chapter2.ScalarData
Section2.1.Numbers
Section2.2.Strings
Section2.3.Perl'sBuilt-inWarnings
Section2.4.ScalarVariables
Section2.5.Outputwithprint
Section2.6.TheifControlStructure
Section2.7.GettingUserInput
Section2.8.ThechompOperator
Section2.9.ThewhileControlStructure














































































Section2.10.TheundefValue
Section2.11.ThedefinedFunction
Section2.12.Exercises
Chapter3.ListsandArrays
Section3.1.AccessingElementsofanArray
Section3.2.SpecialArrayIndices
Section3.3.ListLiterals
Section3.4.ListAssignment
Section3.5.InterpolatingArraysintoStrings
Section3.6.TheforeachControlStructure
Section3.7.ScalarandListContext
Section3.8.inListContext
Section3.9.Exercises
Chapter4.Subroutines
Section4.1.DefiningaSubroutine
Section4.2.InvokingaSubroutine
Section4.3.ReturnValues
Section4.4.Arguments
Section4.5.PrivateVariablesinSubroutines
Section4.6.Variable-LengthParameterLists
Section4.7.NotesonLexical(my)Variables
Section4.8.TheusestrictPragma
Section4.9.ThereturnOperator
Section4.10.Non-ScalarReturnValues
Section4.11.Exercises
Chapter5.InputandOutput
Section5.1.InputfromStandardInput
Section5.2.InputfromtheDiamondOperator
Section5.3.TheInvocationArguments
Section5.4.OutputtoStandardOutput
Section5.5.FormattedOutputwithprintf
Section5.6.Filehandles
Section5.7.OpeningaFilehandle
Section5.8.FatalErrorswithdie
Section5.9.UsingFilehandles
Section5.10.ReopeningaStandardFilehandle
Section5.11.Exercises
Chapter6.Hashes
Section6.1.WhatIsaHash?













































































Section6.2.HashElementAccess
Section6.3.HashFunctions
Section6.4.TypicalUseofaHash
Section6.5.Exercises
Chapter7.IntheWorldofRegularExpressions
Section7.1.WhatAreRegularExpressions?
Section7.2.UsingSimplePatterns
Section7.3.CharacterClasses
Section7.4.Exercises
Chapter8.MatchingwithRegularExpressions
Section8.1.Matcheswithm//
Section8.2.OptionModifiers
Section8.3.Anchors
Section8.4.TheBindingOperator,=~
Section8.5.InterpolatingintoPatterns
Section8.6.TheMatchVariables
Section8.7.GeneralQuantifiers
Section8.8.Precedence
Section8.9.APatternTestProgram
Section8.10.Exercises
Chapter9.ProcessingTextwithRegularExpressions
Section9.1.Substitutionswiths///
Section9.2.ThesplitOperator
Section9.3.ThejoinFunction
Section9.4.m//inListContext
Section9.5.MorePowerfulRegularExpressions
Section9.6.Exercises
Chapter10.MoreControlStructures
Section10.1.TheunlessControlStructure
Section10.2.TheuntilControlStructure
Section10.3.ExpressionModifiers
Section10.4.TheNakedBlockControlStructure
Section10.5.TheelsifClause
Section10.6.AutoincrementandAutodecrement
Section10.7.TheforControlStructure
Section10.8.LoopControls
Section10.9.LogicalOperators
Section10.10.Exercise
Chapter11.FileTests














































































Section11.1.FileTestOperators
Section11.2.ThestatandlstatFunctions
Section11.3.ThelocaltimeFunction
Section11.4.BitwiseOperators
Section11.5.UsingtheSpecialUnderscoreFilehandle
Section11.6.Exercises
Chapter12.DirectoryOperations
Section12.1.MovingAroundtheDirectoryTree
Section12.2.Globbing
Section12.3.AnAlternateSyntaxforGlobbing
Section12.4.DirectoryHandles
Section12.5.RecursiveDirectoryListing
Section12.6.ManipulatingFilesandDirectories
Section12.7.RemovingFiles
Section12.8.RenamingFiles
Section12.9.LinksandFiles
Section12.10.MakingandRemovingDirectories
Section12.11.ModifyingPermissions
Section12.12.ChangingOwnership
Section12.13.ChangingTimestamps
Section12.14.Exercises
Chapter13.StringsandSorting
Section13.1.FindingaSubstringwithindex
Section13.2.ManipulatingaSubstringwithsubstr
Section13.3.FormattingDatawithsprintf
Section13.4.AdvancedSorting
Section13.5.Exercises
Chapter14.ProcessManagement
Section14.1.ThesystemFunction
Section14.2.TheexecFunction
Section14.3.TheEnvironmentVariables
Section14.4.UsingBackquotestoCaptureOutput
Section14.5.ProcessesasFilehandles
Section14.6.GettingDownandDirtywithfork
Section14.7.SendingandReceivingSignals
Section14.8.Exercises
Chapter15.PerlModules
Section15.1.FindingModules
Section15.2.InstallingModules















































































Section15.3.UsingSimpleModules
Section15.4.Exercise
Chapter16.SomeAdvancedPerlTechniques
Section16.1.TrappingErrorswitheval
Section16.2.PickingItemsfromaListwithgrep
Section16.3.TransformingItemsfromaListwithmap
Section16.4.UnquotedHashKeys
Section16.5.Slices
Section16.6.Exercise
ExerciseAnswers
SectionA.1.AnswerstoChapter2Exercises
SectionA.2.AnswerstoChapter3Exercises
SectionA.3.AnswerstoChapter4Exercises
SectionA.4.AnswerstoChapter5Exercises
SectionA.5.AnswerstoChapter6Exercises
SectionA.6.AnswerstoChapter7Exercises
SectionA.7.AnswerstoChapter8Exercises
SectionA.8.AnswerstoChapter9Exercises
SectionA.9.AnswertoChapter10Exercise
SectionA.10.AnswerstoChapter11Exercises
SectionA.11.AnswerstoChapter12Exercises
SectionA.12.AnswerstoChapter13Exercises
SectionA.13.AnswerstoChapter14Exercises
SectionA.14.AnswertoChapter15Exercise
SectionA.15.AnswertoChapter16Exercise
BeyondtheLlama
SectionB.1.FurtherDocumentation
SectionB.2.RegularExpressions
SectionB.3.Packages
SectionB.4.ExtendingPerl'sFunctionality
SectionB.5.SomeImportantModules
SectionB.6.Pragmas
SectionB.7.Databases
SectionB.8.OtherOperatorsandFunctions
SectionB.9.Mathematics
SectionB.10.ListsandArrays
SectionB.11.BitsandPieces
SectionB.12.Formats
SectionB.13.NetworkingandIPC
















































SectionB.14.Security
SectionB.15.Debugging
SectionB.16.TheCommonGatewayInterface(CGI)
SectionB.17.Command-LineOptions
SectionB.18.Built-inVariables
SectionB.19.SyntaxExtensions
SectionB.20.References
SectionB.21.TiedVariables
SectionB.22.OperatorOverloading
SectionB.23.DynamicLoading
SectionB.24.Embedding
SectionB.25.ConvertingOtherLanguagestoPerl
SectionB.26.ConvertingfindCommandLinestoPerl
SectionB.27.Command-LineOptionsinYourPrograms
SectionB.28.EmbeddedDocumentation
SectionB.29.MoreWaystoOpenFilehandles
SectionB.30.LocalesandUnicode
SectionB.31.ThreadsandForking
SectionB.32.GraphicalUserInterfaces(GUIs)
SectionB.33.AndMore...
Colophon

AbouttheAuthors

Colophon
Index


LearningPerl,FourthEdition
byRandalL.Schwartz,TomPhoenix,andbriandfoy
Copyright©2005,2001,1997,1993O'ReillyMedia,Inc.All
rightsreserved.PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reillybooksmaybepurchasedforeducational,business,or
salespromotionaluse.Onlineeditionsarealsoavailablefor
mosttitles(safari.oreilly.com).Formoreinformation,contact
ourcorporate/institutionalsalesdepartment:(800)998-9938or
corporate@oreilly.com.
Editor:

TatianaApandiandAllisonRandal

ProductionEditor:

MattHutchinson

ProductionServices:

GEX,Inc.

CoverDesigner:

EdieFreedman

InteriorDesigner:

DavidFutato

PrintingHistory:



November1993:

FirstEdition.

July1997:

SecondEdition.

July2001:

ThirdEdition.

July2005:

FourthEdition.


NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
LearningPerl,theimageofallama,andrelatedtradedressare
trademarksofO'ReillyMedia,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
ISBN:0-596-10105-8
[M]


Preface
WelcometothefourtheditionofLearningPerl.
Ifyou'relookingforthebestwaytospendyourfirst30to45
hourswiththePerlprogramminglanguage,you'vefoundit.In
thepagesthatfollow,you'llfindacarefullypacedintroduction
tothelanguagethatistheworkhorseoftheInternet,aswellas
thelanguageofchoiceforsystemadministrators,webhackers,
andcasualprogrammersaroundtheworld.
Wecan'tgiveyouallofPerlinjustafewhours.Thebooksthat
promisethisareprobablyfibbingabit.Instead,we'vecarefully
selectedausefulsubsetofPerlforyoutolearn,goodfor
programsfromoneto128lineslong,whichendupbeingabout
90%oftheprogramsinuseoutthere.Andwhenyou'reready
togoon,youcangettheAlpacabook,whichpicksupwhere
thisbookleavesoff.We'vealsoincludedanumberofpointers
forfurthereducation.
Eachchapterissmallenoughsoyoucanreaditinanhouror
two.Eachchapterendswithaseriesofexercisestohelpyou
practicewhatyou'velearned,withtheanswersinAppendixA
foryourreference.Thus,thisbookisideallysuitedfora
classroom"IntroductiontoPerl"course.Weknowthisbecause
thematerialforthisbookwasliftedalmostword-for-wordfrom
ourflagship"LearningPerl"coursedeliveredtothousandsof
studentsaroundtheworld.However,we'vedesignedthebook
forself-studyaswell.
Perllivesasthe"toolboxforUnix,"butyoudon'thavetobea
UnixguruoraUnixusertousethisbook.Unlessotherwise
noted,everythingwe'resayingappliesequallywelltoWindows
ActivePerlfromActiveStateandmostothermodern
implementationsofPerl.


Thoughyoudon'tneedtoknowaboutPerltobeginreadingthis
book,werecommendthatyouhavefamiliaritywithbasic
programmingconceptssuchasvariables,loops,subroutines,
andarrays,andtheall-important"editingasourcecodefile
withyourfavoritetexteditor."Wedon'tspendanytime
explainingthoseconcepts.We'repleasedthatwe'vehadmany
reportsofpeoplesuccessfullypickingupLearningPerland
graspingPerlastheirfirstprogramminglanguage,butwecan't
promisethesameresultsforeveryone.


HistoryofThisBook
Forthecurious,here'showRandaltellsthestoryofhowthis
bookcameabout:
AfterIhadfinishedthefirstProgrammingPerlbookwithLarry
Wall(in1991),IwasapproachedbyTaosMountainSoftwarein
SiliconValleytoproduceatrainingcourse.Thisincludedhaving
medeliverthefirstdozenorsocoursesandtrainitsstaffto
continueofferingthecourse.Iwrotethecourseforthe
company[*]anddelivereditaspromised.
[*]Inthecontract,Iretainedtherightstotheexercises,hopingsomedaytoreusetheminsomeotherway,like
inthemagazinecolumnsIwaswritingatthetime.TheexercisesaretheonlythingsthatleaptfromtheTaos
coursetothebook.

Onthethirdorfourthdeliveryofthatcourse(inlate1991),
someonecameuptomeandsaid,"Youknow,Ireallylike
ProgrammingPerl,butthewaythematerialispresentedinthis
courseissomucheasiertofollow.Yououghttawriteabooklike
thiscourse."Itsoundedlikeanopportunitytome,soIstarted
thinkingaboutit.
IwrotetoTimO'Reillywithaproposalbasedonanoutlinethat
wassimilartothecourseIwaspresentingforTaos,thoughI
hadrearrangedandmodifiedafewofthechaptersbasedon
observationsintheclassroom.Ithinkthatwasmyfastest
proposalacceptanceinhistory;IgotamessagefromTim
within15minutessaying,"We'vebeenwaitingforyoutopitch
asecondbookProgrammingPerlissellinglikegangbusters."
Thatstartedtheeffortoverthenext18monthstofinishthe
firsteditionofLearningPerl.
Duringthattime,Iwasstartingtoseeanopportunitytoteach
PerlclassesoutsideSiliconValley,[ ]soIcreatedaclassbased
onthetextIwaswritingforLearningPerl.Igaveadozen


classesforvariousclients(includingmyprimarycontractor,
IntelOregon),andusedthefeedbacktofine-tunethebook
draftevenfurther.
[ ]MyTaoscontracthadano-competeclause,soIhadtostayoutofSiliconValleywithanysimilarcourses,
whichIrespectedformanyyears.

ThefirsteditionhitthestreetsonthefirstdayofNovember
1993[ ]andbecameasmashingsuccess,frequentlyeven
outpacingProgrammingPerlbooksales.
[ ]Irememberthatdatewell,becauseitwasalsothedayIwasarrestedatmyhomeforcomputer-related
activitiesaroundmyIntelcontract,aseriesoffelonychargesforwhichIwaslaterconvicted.See
http://www.lightlink.com/fors/fordetails.

Theback-coverjacketofthefirstbooksaid"writtenbya
leadingPerltrainer."Well,thatbecameaself-fulfillingprophesy.
Withinafewmonths,Iwasstartingtogetemailfrompeopleall
overtheUnitedStatesaskingmetoteachattheirsite.During
thefollowingsevenyears,mycompanybecametheleading
worldwideon-sitePerltrainingcompany,andIhadpersonally
rackedup(literally)amillionfrequent-fliermiles.Itdidn'thurt
thattheWebstartedtakingoffaboutthen,andthewebmasters
andwebmistressespickedPerlasthelanguageofchoicefor
contentmanagement,interactionthroughCGI,and
maintenance.
Fortwoyears,IworkedcloselywithTomPhoenixinhisroleas
leadtrainerandcontentmanagerforStonehenge,givinghim
chartertoexperimentwiththe"Llama"coursebymovingthings
aroundandbreakingthingsup.Whenwehadcomeupwith
whatwethoughtwasthebestmajorrevisionofthecourse,I
contactedO'Reillyandsaid"it'stimeforanewbook!"Andthat
becamethethirdedition.
TwoyearsafterwritingthethirdeditionoftheLlama,TomandI
decideditwastimetopushourfollow-on"advanced"course
outintotheworldasabookforpeoplewritingprogramsthat


are"100to10,000linesofcode."Andtogetherwecreatedthe
firstAlpacabook,releasedin2003.
Butfellowinstructorbriandfoywasjustgettingbackfromthe
conflictintheGulf,andhehadnoticedthatwecouldusesome
rewritinginbothbooksbecauseourcoursewareneededtotrack
thechangingneedsofthetypicalstudent.So,hepitchedthe
ideatoO'ReillytotakeonrewritingboththeLlamaandthe
AlpacaonefinaltimebeforePerl6(wehope).Thiseditionof
theLlamareflectsthosechanges.brianhasbeentheleadwriter
here,workingwithmyoccasionalguidance,andhasdonea
brillantjoboftheusual"herdingcats"thatamultiple-writer
teamgenerallyfeelslike.
Someofthedifferencesyoumaynoticefromprioreditions:
ThetexthasbeenupdatedforthelatestversionofPerl,Perl
5.8.
We'vecombinedsomechapters,andrenumberedothers.
We'vebeefeduptheregularexpressionchaptersand
introducedfilehandlessooner.
We'veaddedachapteronCPAN,whichhasbecomemuch
moreimportanttobeginners.


TypographicalConventions
Thefollowingfontconventionsareusedinthisbook:

Constantwidth
Isusedformethodnames,functionnames,variables,and
attributes.Itisalsousedforcodeexamples.

Constantwidthbold
Isusedtoindicateuserinput.

Constantwidthitalic

Isusedtoindicateareplaceableitemincode(e.g.,filename,
whereyouaresupposedtosubstituteanactualfilename).

Italic
Isusedforfilenames,URLs,hostnames,importantwords
onfirstmention,andemphasis.

Footnotes
Areusedtoattachparentheticalnotesthatyoushouldnot
readonyourfirst(orperhapssecondorthird)readingof
thisbook.Sometimesliesarespokentosimplifythe


presentation,andthefootnotesrestorethelietotruth.
Oftenthematerialinthefootnotewillbeadvancedmaterial
notdiscussedanywhereelseinthebook.


UsingCodeExamples
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"LearningPerl,FourthEdition,byRandalL.Schwartz,
TomPhoenix,andbriandfoy.Copyright2005O'ReillyMedia,
Inc.,0-596-10105-8."


HowtoContactUs
Wehavetestedandverifiedalltheinformationinthisbookto
thebestofourabilities,butyoumayfindthatfeatureshave
changedorthatwehaveleterrorsslipthroughtheproduction
ofthebook.Pleaseletusknowofanyerrorsthatyoufind,as
wellassuggestionsforfutureeditions,bywritingto:
O'ReillyMedia,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
(800)998-9938(intheU.S.orCanada)
(707)829-7000(international/local)
(707)829-0104(fax)
Youcanalsosendmessageselectronically.Tobeputonour
mailinglistortorequestacatalog,sendemailto:
info@oreilly.com
Toasktechnicalquestionsortocommentonthebook,send
emailto:
bookquestions@oreilly.com
Wehaveawebsiteforthebook,wherewe'lllistexamples,
errata,andanyplansforfutureeditions.Italsooffersa
downloadablesetoftextfiles(andacoupleofPerlprograms)
thatareuseful,butnotrequired,whendoingsomeofthe
exercises.Youcanaccessthispageat:
http://www.oreilly.com/catalog/lperl4/
Formoreinformationaboutthisbookandothers,seethe
O'Reillywebsite:
http://www.oreilly.com


SafariEnabled

WhenyouseeaSafari®enabledicononthecoverof
yourfavoritetechnologybook,thatmeansthebookisavailable
onlinethroughtheO'ReillyNetworkSafariBookshelf.
Safarioffersasolutionthat'sbetterthane-books.It'savirtual
librarythatletsyoueasilysearchthousandsoftoptechbooks,
cutandpastecodesamples,downloadchapters,andfindquick
answerswhenyouneedthemostaccurate,currentinformation.
Tryitfreeathttp://safari.oreilly.com.


Acknowledgments
ThankstoourreviewersDavidH.Adler,DaveCross,Chris
Devers,PaulFenwick,StephenJenkins,MatthewMusgrove,and
WilWheatonforprovidingcommentsonthedraftofthisbook.
Thankstoourmanystudentswhohaveletusknowwhatparts
ofthecoursematerialhaveneededimprovementoverthe
years.It'sbecauseofyouthatwe'reallsoproudofittoday.
ThankstothemanyPerlMongerswhohavemadeusfeelat
homeaswe'vevisitedyourcities.Let'sdoitagainsometime.
Andfinally,oursincerestthankstoourfriendLarryWall,for
havingthewisdomtosharehiscoolandpowerfultoyswiththe
restoftheworldsothatwecanallgetourworkdonejusta
littlebitfaster,easier,andwithmorefun.

FromRandal
IwanttothanktheStonehengetrainerspastandpresent
(JosephHall,TomPhoenix,ChipSalzenberg,briandfoy,and
TadMcClellan)fortheirwillingnesstogooutandteachinfront
ofclassroomsweekafterweekandtocomebackwiththeir
notesaboutwhat'sworkingsowecouldfine-tunethematerial
forthisbook.Iespeciallywanttosingleoutmycoauthorand
businessassociate,TomPhoenix,forhavingspentmanyhours
workingtoimproveStonehenge'sLlamacourseandtoprovide
thewonderfulcoretextformostofthisbook.Andbriandfoy
forbeingtheleadwriterofthefourthedition,includingtaking
thateternalto-doitemoutofmyinboxsothatitwouldfinally
happen.
IwanttothankeveryoneatO'Reilly,especiallyourverypatient


editorandoverseer,AllisonRandal(norelation,butshehasa
nicelyspelledlastname),andTimO'Reillyfortakingachance
onmeinthefirstplacewiththeCamelandLlamabooks.
Iamalsoindebtedtothethousandsofpeoplewhohave
purchasedthepasteditionsoftheLlamasothatIcouldusethe
moneytostay"offthestreetsandoutofjail,"andtothose
studentsinmyclassroomswhohavetrainedmetobeabetter
trainer,andtothestunningarrayofFortune1000clientswho
havepurchasedourclassesinthepastandwillcontinuetodo
sointothefuture.
Asalways,aspecialthankstoLyleandJack,forteachingme
nearlyeverythingIknowaboutwriting.Iwon'teverforgetyou
guys.

FromTom
I'vegottoechoRandal'sthankstoeveryoneatO'Reilly.Forthe
thirdeditionofthisbookLindaMuiwasoureditor,andIstill
thankherforherpatienceinpointingoutwhichjokesand
footnotesweremostexcessivewhilepointingoutthatsheisin
nowaytoblamefortheonesthatremain.SheandRandalhave
guidedmethroughtheprocessofwriting,andIamgrateful.In
thepresentedition,AllisonRandalhassteppedinaseditor,and
mythanksgotoheraswell.
AndanotherechowithregardtoRandalandtheother
Stonehengetrainers,whohardlyevercomplainedwhenI
unexpectedlyupdatedthecoursematerialstotryanew
teachingtechnique.Youfolkshavecontributedmanydifferent
viewpointsonteachingmethodsthatIwouldneverhaveseen.
Formanyyears,IworkedattheOregonMuseumofScience
andIndustry(OMSI),andI'dliketothankthefolkstherefor
lettingmehonemyteachingskillsasIlearnedtobuildajoke


ortwointoeveryactivity,explosion,ordissection.
TothemanyfolksonUsenetwhohavegivenmeyour
appreciationandencouragementformycontributionsthere,
thanks.Asalways,Ihopethishelps.
Tomymanystudents,whohaveshownmewiththeirquestions
(andbefuddledlooks)whenIneededtotryanewwayof
expressingaconcept.Ihopethatthepresenteditionhelpsto
relieveanyremainingpuzzlement.
Ofcourse,deepthanksaredueespeciallytomycoauthor,
Randal,forgivingmethefreedomtotryvariouswaysof
presentingthematerialintheclassroomandhereinthebook,
aswellasforthepushtomakethismaterialintoabookinthe
firstplace.Andwithoutfail,ImustsaythatIamindeed
inspiredbyyourongoingworktoensurenooneelsebecomes
ensnaredbythelegaltroublesthathavestolensomuchofyour
timeandenergy;you'reafineexample.
Tomywife,Jenna,thanksforbeingacatperson,and
everythingthereafter.

Frombrian
IhavetothankRandalfirstsinceIlearnedPerlfromthefirst
editionofthisbookandthenhadtolearnitagainwhenhe
askedmetostartteachingforStonehengein1998.Teachingis
oftenthebestwaytolearn.Sincethen,Randalhasmentored
meinPerlandseveralotherthingshethoughtIneededto
learn,likethetimehedecidedthatwecoulduseSmalltalk
insteadofPerlforademonstrationatawebconference.I'm
alwaysamazedatthebreadthofhisknowledge.He'stheone
whotoldmetostartwritingaboutPerl.NowI'mhelpingouton
thebookwhereIstarted.I'mhonored,Randal.


I'dprobablyonlyseenTomPhoenixforfewerthantwoweeksin
theentiretimeI'veworkedforStonehenge,butI'dbeen
teachinghisversionofourLearningPerlcourseforyears.That
versionturnedintothethirdeditionofthisbook.Byteaching
Tom'snewversion,Ifoundnewwaystoexplainalmost
everythingandlearnedevenmorecornersofPerl.
WhenIconvincedRandalthatIshouldhelpoutontheLlama
update,Iwasanointedasthemakeroftheproposaltothe
publisher,thekeeperoftheoutline,andtheversioncontrol
wrangler.Oureditor,AllisonRandal,helpedmegetallofthose
setupandenduredmyfrequentemailswithoutcomplaining.
Specialnon-PerlthankstoStacey,Buster,Mimi,Roscoe,Amelia,
Lila,andeveryoneelsewhotriedtodistractmewhileIwas
busybutstilltalkedtomeeventhoughIcouldn'tcomeoutto
play.


Chapter1.Introduction
WelcometotheLlamabook!
Thisisthefourtheditionofabookthathasbeenenjoyedby
halfamillionreaderssince1993.Atleast,wehopethey've
enjoyedit.It'sasurethingthatwe'veenjoyedwritingit.[*]
[*]Tobesure,thefirsteditionwaswrittenbyRandalL.Schwartz,thesecondbyRandalandTomChristiansen,
thethirdbyRandalandTomPhoenix,andnowthefourthbyRandal,TomPhoenix,andbriandfoy.So,
wheneverwesay"we"inthisedition,wemeanthatlastgroup.Now,ifyou'rewonderinghowwecansaythat
we'veenjoyedwritingit(inthepasttense)whenwe'restillonthefirstpage,that'seasy:westartedattheend,
andworkedourwaybackward.Itsoundslikeastrangewaytodoit,weknow.But,honestly,oncewefinished
writingtheindex,therestwaseasy.


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay

×

×