Special Variables - PERL - kichwa.com
文章推薦指數: 80 %
$], 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
延伸文章資訊
- 1What are special variables in Perl? - Educative.io
These special variables are usually represented by using punctuation symbols right after a variab...
- 2Perl Special Variables - CodesCracker
Special variables are predefined having special meaning in perl. The special variables in perl, u...
- 3Special Variables - Perl 101
Perl has rich signal handling capabilities; using the %SIG variable, you can make any subroutine ...
- 4Perl's Special Variables
One of the best ways to make your Perl code look more like … well, like Perl code – and not like ...
- 5Perl - Special Variables - Tutorialspoint
There are some variables which have a predefined and special meaning in Perl. They are the variab...