Perl Special Variables - CodesCracker

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

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:



請為這篇文章評分?