Perl Special Variables - CodesCracker
文章推薦指數: 80 %
Special variables are predefined having special meaning in perl. The special variables in perl, uses punctuation characters after the usual variable ... PerlBasics PerlHome PerlBasicSyntax PerlDataTypes PerlVariables PerlScalars PerlArrays PerlHashes PerlIf-Else PerlLoops PerlOperators PerlReferences PerlSubroutines PerlFormats PerlDate&Time PerlFileI/O PerlAdvanced PerlDirectory PerlRegularExpressions PerlSpecialVariables PerlSocketProgramming PerlSendE-mail PerlObjectOriented PerlErrorHandling PerlCGIProgramming PerlDatabase PerlPackages&Modules PerlProcessManagement PerlTest PerlOnlineTest GiveOnlineTest AllTestList PerlSpecialVariables Specialvariablesarepredefinedhavingspecialmeaninginperl.Thespecialvariablesinperl,usespunctuationcharacters aftertheusualvariableindicatorusingdollar($),at(@),orpercent(%)sign,like$_. PerlSpecialVariableExample Themostcommonlyusedspecialvariableinperlis$_,containsthedefaultinputandpattern-searchingstring.Hereisanexample usingspecialvariable$_inperl: #!/usr/bin/perl foreach('Deepak','Rajat','Ritesh') { print($_); print("\n"); } Whentheabovecodeisexecuted,itwillproducethefollowingoutput: Deepak Rajat Ritesh PerlSpecialVariableTypes Therearethefollowingtypesofspecialvariablesavailableinperl: RegularExpressionSpecialVariables FilehandleSpecialVariables GlobalScalarSpecialVariables GlobalHashSpecialVariables GlobalArraySpecialVariables GlobalSpecialConstants GlobalSpecialFilehandles PerlGlobalScalarSpecialVariables Herethefollowingtablelistsallthescalarspecialvariablesavailableinperl. SpecialVariableSymbol Meaning $_ Thisspecialvariablerepresentsthedefaultinputandpattern-searchingspace $ Thisspecialvariablerepresentsthecurrentinputlinenumberoflastfilehandlethatwasread $/ Thisspecialvariablerepresentstheinputrecordseparator,newlinebydefault $, Thisspecialvariablerepresentstheoutputfieldseparatorfortheoperator,print $\ Thisspecialvariablerepresentstheoutputrecordseparatorfortheoperator,print $" Thisspecialvariableissimilartothe"$,"specialvariable,butinthiscase,itappliestothelistvaluesinterpolated intoadouble-quotedstrings.Thedefaultisaspace $; Thisspecialvariablerepresentsthesubscriptseparatorforthemultidimensionalarrayemulation.Thedefaultis"\034" $^L Thisspecialvariableisusedtoperformaformfeed.Thedefaultis"\f" $: Thisspecialvariablerepresentsthecurrentsetofcharactersafterwhichthestringmaybebrokentofillthecontinuationfields (startingwithsymbol,^)inaformat.Thedefaultis"\n" $^A Thisspecialvariablerepresentsthecurrentvalueofthewriteaccumulatorfortheformatlines $# Thisspecialvariablecontainstheoutputformatfortheprintednumbers $? Thisspecialvariablerepresentsthestatusreturnedbythelastpipeclose,backtickcommand,orsystemoperator $! Ifthisspecialvariableusedinanumericcontext,yieldsthecurrentvalueofthevariable,errno,identifyingthelastsystemcallerror. Ifusedinastringcontext,yieldsthecorrespondingsystemerrorstring $@ Thisspecialvariablerepresentstheperlsyntaxerrormessagefromthelastevalcommand $$ Thisspecialvariablerepresentsthepidoftheperlprocess,runningthisscript $< ThisspecialvariablerepresentstherealuserIDofthisprocess $> ThisspecialvariablerepresentstheuserIDofthisprocess $( ThisspecialvariablerepresentstherealgroupIDofthisprocess $) Thisspecialvariablerepresentstheeffectivegidofthisprocess $0 Thisspecialvariablecontainsthenameofthefilecontainingtheperlscriptbeingexecuted $[ Thisspecialvariablerepresentstheindexofthefirstelementinanarrayandofthefirstcharacterinasubstring.Thedefaultis0 $] Thisspecialvariablereturnstheversionpluspatchlevel,dividedby1000 $^D Thisspecialvariablerepresentsthecurrentvalueofdebuggingflags $^E Thisspecialvariablerepresentsanextendederrormessageonvariousplatforms $^F Thisspecialvariablerepresentsthemaximumsystemfiledescriptor,ordinarily2 $^H Thisspecialvariablecontainstheinternalcompilerhints,enabledbycertainpragmaticmodules $^I Thisspecialvariablerepresentsthecurrentvalueoftheinplace-editextension $^M Thisspecialvariablerepresentsthecontentsof$Mcanbeusedasanemergencymemorypoolincaseifperldieswithanout-of-memoryerror. $^O Thisspecialvariablecontainsthenameoftheoperatingsystemthatthecurrentperlbinarywascompiledfor $^P Thisspecialvariablerepresentstheinternalflag,thedebuggerclearssothatitdoesnotdebugitself $^T Thisspecialvariablerepresentsthetimeatwhichthescriptstartsrunning,insecondssincetheepoch $^W Thisspecialvariablerepresentsthecurrentvalueofthewarningswitch,eithertrueorfalse $^X Thisspecialvariablerepresentsthenamethattheperlbinaryitselfwasexecutedas PerlGlobalArraySpecialVariables Here,thefollowingtableliststheglobalarrayspecialvariablesavailableinperl: SpecialVariable Meaning @ARGV Thisspecialvariablerepresentsthearraycontainingthecommandlineargumentsintendedforscript @F Thisspecialvariablerepresentsthearrayintowhichtheinputlinesaresplitwhenthe-acommandlineswitchisgiven @INC Thisspecialvariablerepresentsthearraycontainingthelistofplacestolookfortheperlscriptstobeevaluatedbythedo,require oruseconstructs PerlGlobalHashSpecialVariables Here,thefollowingtableliststheglobalhashspecialvariablesavailableinperl: SpecialVariable Meaning %INC Thisspecialvariablerepresentsthehashcontainingentriesforthefilenameofeachfile,whichhasbeincludedviadoorrequire %SIG Thisspecialvariablerepresentsthehashusedtosetthesignalhandlersforthevarioussignals %ENV Thisspecialvariablerepresentsthehashcontainingyourcurrentenvironment PerlGlobalSpecialFilehandles Here,thefollowingtableliststheglobalspecialfilehandlesavailableinperl: SpecialVariable Meaning ARGV Thisspecialvariablerepresentsthespecialfilehandlethatiteratesoverthecommandlinefilenamesin@ARGV STDIN Thisspecialvariablerepresentsthespecialfilehandleforthestandardinputinanypackage STDERR Thisspecialvariablerepresentsthespecialfilehandleforthestandarderrorinanypackage STDOUT Thisspecialvariablerepresentsthespecialfilehandleforthestandardoutputinanypackage _ Thisspecialvariablerepresentsthespecialfilehandleusedtocachetheinformationfromthestat,lstat,last,orfiletestoperator DATA Thisspecialvariablerepresentsthespecialfilehandle,referstoanythingfollowedthe_END_tokeinthefilecontainingthescript PerlRegularExpressionSpecialVariables Herethetablegivenbelow,liststheregularexpressionspecialvariablesavailableinperl: SpecialVariable Meaning $& Thisspecialvariablerepresentsthestringmatchedbythelastsuccessfulpatternmatch $` Thisspecialvariablerepresentsthestringprecedingwhateverwasmatchedbythelastsuccessfulpatternmatch $' Thisspecialvariablerepresentsthestringfollowingwhateverwasmatchedbythelastsuccessfulpatternmatch $+ Thisspecialvariablerepresentsthelastbracketmatchedbythelastsearchpattern PerlFilehandleSpecialVariables Herethefollowingtableliststhefilehandlespecialvariablesavailableinperl: SpecialVariable Meaning $| Ifthisspecialvariablesettonon-zero,forcesfflush(3)aftereverywriteorprintonthecurrentlyselectedoutputchannel $% Thisspecialvariablerepresentsthecurrentpageno.ofthecurrentlyselectedoutputchannel $= Thisspecialvariablerepresentsthecurrentpagelengthofthecurrentlyselectedchannel.Thedefaultis60 $- Thisspecialvariablerepresentsthenumberoflinesleftonthepageofthecurrentlyselectedoutputchannel $~ Thisspecialvariablerepresentsthenameofthecurrentreportformatforthecurrentlyselectedchannel.Thedefaultisthe nameofthefilehandle $^ Thisspecialvariablerepresentsthenameofthecurrenttopofthepageformatforthecurrentlyselectedoutputchannel. PerlOnlineTest«PreviousTutorial NextTutorial» PleaseShare:
延伸文章資訊
- 1Perl predefined variables - Perldoc Browser
CONTENTS. General Variables; Variables related to regular expressions; Variables related to fileh...
- 2Perl - Special Variables - Tutorialspoint
There are some variables which have a predefined and special meaning in Perl. They are the variab...
- 3Special Variables - Perl 101
Perl has rich signal handling capabilities; using the %SIG variable, you can make any subroutine ...
- 4Perl Special Variables - CodesCracker
Special variables are predefined having special meaning in perl. The special variables in perl, u...
- 5Perl's Special Variables
One of the best ways to make your Perl code look more like … well, like Perl code – and not like ...