ARGV in Perl represents the command-line arguments.

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

Related examples in the same category ; 16. ARGV and the Null Filehandle ; 17. Aliases and Values ; 18. Alternative names for Perl system variables. ; 19. Assign ... HomePerlArrayCGIClassDataTypeDatabaseFileGUIHashLanguageBasicsNetworkRegularExpressionReportStatementStringSubroutineSystemFunctionsWin32XMLARGVinPerlrepresentsthecommand-linearguments.:SpecialVariables « LanguageBasics « PerlPerlLanguageBasicsSpecialVariablesARGVinPerlrepresentsthecommand-linearguments. #representsopeningeachfilethatislistedbynameonthecommandline. #@ARGVisaPerlarraythatcontainseachofthecommand-lineargumentsasaseparatearrayelement. #!/usr/bin/perl-w #Listscommand-linearguments. #Getfirstargument. $arg=shift(@ARGV); #Loopwhilethereisanargument. while(defined$arg){ print"$arg\n"; #Getnextargument. $arg=shift(@ARGV); } Relatedexamplesinthesamecategory1.SpecialLiterals2.Splittingup$_3.Splittingup$_andcreatinganunnamedlist4.Thelistseparatorisacomma5.Thelistseparatoristheemptystring6.PassingArgumentsattheCommandLine7.SpecialHashes:The%ENVHash8.The%SIGhashsetssignalhandlersforsignals.9.Aprogramthatchangesthevalueof$/.10.Aprogramthatusesthe$"(dollarandquotation)variable.11.Aprogramthatusesthe$(dollar),variable.12.Aprogramthatusesthe$together.103.Usingthe$.variable.104.Usingthe$;(dollarandsemicolon)variable.105.Usingthe@_toreferencetheparameter106.UsingtheDefaultVariable$_107.Usingthediamondoperatorwith@ARGV108.Usingtheifstatementtocheckthecommandlineparameters109.UsingthespecialPerlvariable$!inthemessagepassedtodie.110.Usingtrtoconvertallfilenamespassedintouppercase111.Verifythetotalnumberofthecommandlineparameter112.Workingwith$_usuallymakesprogrammingmucheasier,butmoreconfusingtotheuninitiated113.YoudisplaythecurrentlineofexecutioninaPerlscriptbyreferringtoitwiththe__LINE__token.114.YoudisplaythenameofthecurrentPerlpackagewith__PACKAGE__.115.Youdisplaythenameofthecurrentfilewiththe__FILE__token116.foreach(@_)117.foreachloopand$_118.ordie$!119.ordie$^E;120.print"Hello,$ENV{USER}!\n";121.print$INC{'English.pm'};122.print$];(Perlversionnumber)123.printoutallpmlibrarylocation124.printsouteachelementof@ARGVseparately125.shift:[email protected]$^T127.undef$/;



請為這篇文章評分?