Special Variables - PERL - kichwa.com

文章推薦指數: 80 %
投票人數:10人

$], The first part of the string printed out when you say perl -v. It can be used to determine at the beginning of a script whether the Perl interpreter ... SpecialVariables TableofContents Per-filehandleSpecialVariables LocalSpecialVariables GlobalSpecialVariables PleasebearwithmewhileItrytocompletethesepages.I'llgettothem whenIcan. Cheers... Per-filehandleSpecialVariables Thesevariablesneverneedtobementionedinalocal()becausetheyalwaysrefertosomevaluepertainingtothecurrentlyselectedoutputfilehandle-eachfilehandlekeepsitsownsetofvalues. VariableContentsMnemonic $|Ifsettononzero,forcesaflushaftereverywriteorprintWhenyouwantyourpipestobepipinghot $%Currentpagenumber%ispagenumberinnroff $=Currentpagelength=hashorizontallines $-Numberoflinesleftonthepagelines_on_page-lines_printed $~NameofthecurrentreportformatCloselyrelatedto$^ $^Nameofthecurrenttop-of-pageformatPointstotopofpage ReturntoTop LocalSpecialVariables Thesevariablesthatarealwayslocaltothecurrentblock, soyouneverneedtomentiontheminalocal().Allofthemare associatedwiththelastsuccessfulpatternmatch. VariableContentsMnemonic $1..$9 Containsthesubpatternfromthecorrespondingset ofparenthesesinthelastpatternmatchedlike\1..\9 $& Containsthestringmatchedbythelastpatternmatch like&insomeeditors $` Thestringprecedingwhateverwasmatchedbythelast patternmatch,notcountingpatternsmatchedinnestedblocksthathave beenexitedalready. `oftenprecedesaquotedstringinnormal text $' Thestringfollowingwhateverwasmatchedbythelast patternmatch,notcountingpatternsmatchedinnestedblockesthathave beenexitedalready.Forexample:    $_='abcdefghi';   /def/;    print"$`:$&:$'\n";    #printsabc:def:ghi 'oftenfollowsaquotedstringinnormaltext $+ thelastbracketmatchedbythelastsearchpattern. Thisisusefulifyoudon'tknowwhichofasetofalternativepatterns matched.Forexample:     /Version:(.*)|Revision:(.*)/&&($rev=$+); bepositiveandforwardlooking GlobalSpecialVariables Therearequiteafewvariablesthatareglobalinthefullestsense--theymeanthesamethingineverypackage.Ifyouwantaprivatecopyofoneofthem,youmustlocalizeitinthecurrentblock. VariableContentsMnemonic $_ Thedefaultinputandpattern-searchingspace.Thefollowingpairsare equivalent:     while(<>){...   #equivalentonlyinwhile!     while($_=<>){...     /^Subject:/     $_=~/^Subject:/     y/a-z/A-Z/     $_=~y/a-z/A-Z/     chop     chop($_) underlineisunderstoodtobeunderlyingcertainundertakings $. Thecurrentinputlinenumberofthelastfilehandlethatwasread. Remberthatonlyanexplicitcloseonthefilehandleresetsthelinenumber. manyprogramsuse.tomeanthecurrentlinenumber $/ Theinputrecordseparator,newlinebydefault.$/maybesettoavalue longerthanonecharacterinordertomatchamulti-characterdelimiter.If $/isundefined,norecordseparatorismatched,and willreadeverythingtotheendofthecurrentfile. /isusedtodelimitlineboundrieswhenquotingpoetry.Or,ifyou prefer,thinkofmadslasherscuttingthingstoribbons. $\ Theoutputrecordseparatorfortheprintoperator. Youset$\insteadofadding\nattheendoftheprint. $, Theoutputfieldseparatorfortheprintoperator. Whatisprintedwhenthereisa,inyourprintstatement $" Thisissimilarto$,exceptthatitappliestoarrayvaluesinterpolated intoadouble-quotedstring(orsimilarinterpretedstring).Defaultisspace. Obvious,Ithink $# Theoutputformatfornumbersdisplayviatheprintoperator #isthenumbersign $$ TheprocessnumberofthePerlrunningthisscript Sameasshells $? Thestatusreturnedbythelastpipeclose,backtick(``)commandor systemoperator.Notethatthisisthestatuswordreturnedbythe wait()systemcall,sotheexitvalueofthesubprocessisactually ($?>>*).$?&255giveswhichsignal,ifany,theprocess diedfrom,andwhethertherewasacoredump. Similartoshandksh $* Setto1todomulti-linematchingwithinastring,0totellPerlthatit canassumethatstringscontainasingleline,forthepurposeof optimizingpatternmatches.Defaultis0 *matchesmultiplethings $0 ContainsthenameofthefilecontainingthePerlscriptbeingexecuted. DependingonyourOS,itmayormaynotincludethefullpathname. Sameasshandksh $[ Theindexofthefirstelementinanarray,andofthefirstcharacterina substring. [beginssubscripts $] Thefirstpartofthestringprintedoutwhenyousayperl-v.It canbeusedtodetermineatthebeginningofascriptwhetherthePerl interpreterexecutingthescriptisintherightrangeofversions.Ifused inanumericcontext,$]returnsversion+patchlevel/1000. IsthisversionofPerlinthe"rightbracket"? $; Thesubscriptseparatorformulti-dimensionalarrayemulation.Ifyourefer toanassociativearrayelementas:    $foo{$a,$b,$c} itreallymeans:    $foo{join($;,$a,$b,$c)} butdon'tput    @foo{$a,$b,$c} whichmeans    ($foo{$a},$foo{$b},$foo{$c}) Comma(thesyntacticsubscriptseparator)isasemi-semicolon.Yeah,it's prettylame,but$,isalreadytakenforsomethingmoreimportant. $! Ifusedinanumericcontext,yieldsthecurrentvalueoferrno,with alltheusualcaveats.(Thismeansthatyoushouldn'tdependonthevalueof $!tobeanythinginparticularunlessyou'vegottenaspecificerror returnindicatingasystemerror.)Ifusedinastringcontext,yieldsthe correspondingsysemerrorstring. Whatjustwentbang? $@ ThePerlsyntaxerrororroutineerrormessagefromthelasteval,do-FILE, orrequirecommand.Ifset,eitherthecompilationfailed,orthe diefunctionwasexecutedwithinthecodeoftheeval. Wherewasthesyntaxerrorat? ReturntoTop



請為這篇文章評分?