欢迎来到天天文库
浏览记录
ID:22100486
大小:170.50 KB
页数:83页
时间:2018-10-27
《perl使用介绍》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Perl使用介紹What’sPerlWhatisPerl?PracticalExtractionPerlLanguagePathologicallyElectricRubbishListerPracticallyEverythingReallyLikeableshells,awk,sed,grep,CWhat’sPerlfor?Manipulatetextinfiles,extractdatafromfileswritereportsMultiplePlatformPerlScriptsPerlattheCommandLineScriptSetupTheScri
2、ptPerlattheCommandLineWhereisPerl?/usr/local/binThe‘-e’switch:由CommandLine執行Perl$perl-e‘print“hellodolly”’;The‘-n’Switch:對檔案的每一行執行相同的動作Example1The‘-c’Switch:檢查Script的語法$perl-ce‘printif/Igor’emp.first$perl-ce‘printif/Igor/’emp.firstScriptSetupStatementsareterminatedwithasemicolon(;)
3、只有子程式(subroutine)與報告(reportformat)需要先宣告Variable不需先宣告Initialize為0或空字串(‘’)TheScriptStartup:Script的第一行寫上#!#!/usr/local/bin/perlComments:#SampleScript:ex2.perl如果第一行沒加上#!?perlPrintingFileHandleWordsTheprintFunctionTheprintfFunctionFileHandleThethreepredefinedfilehandle
4、s::StandardInput:StandardOutput:StandardErrorTheprintandprintffunctionssendtheiroutputbydefaulttotheSTDOUTfilehandleWords大小寫不同(casesensitive)Quotes單引號:不做任何變數或特殊字元的轉換雙引號$,$,@,%常數(Literal,Constant)數值常數123450x456fff(16進位)0777(8進位)23.45.234E-2字串常數t
5、rfbae 33xffluLUE\常數(Cont.)特殊常數_LINE_:CurrentLineNumber_FILE_:CurrentFileName_END_:Logicalendofthescript;trailinggarbageisignoredTheprintFunctionExample3PrintingLiterals:Example4,5TheprintfFunctionThesameasinCFormatSpecifiers(Example6)c:Characters:Stringd:Decimal;ld:LongDe
6、cimalu:UnsignedDecimal;lu:LongUnsignedDecimalx:Hex;lx:LongHexo:Octal;lo:LongOctale:ScientificNotationf:FloatingPointg:eorf(whichtakestheleastspace)What’sinaName?AboutPerlvariablesScalars,Arrays,andAssociativeArraysReadingfromSTDINArrayFunctionsAssociativeArrayFunctionsAboutPerlVariab
7、lesTypesscalar,array,andassociativearrayScopeandPackageDefaultglobalinscopeNamingConventions$var-->Scalarvariable@var-->Arrayvariable%var-->AssociativevariableCasesensitive初始值為0或空字串AboutPerlVariables(Cont.)Example7QuotingRules(Example8)“…”scalarvariable與array會換成該有的值Associativearray不會
8、換t,,…等一定要
此文档下载收益归作者所有