defaults to shifting @ARGV : Special Variables - Perl

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

#!/usr/bin/perl -w use strict; sub version { print "version\n"; } my $option = shift; # defaults to shifting @ARGV version() if $option eq "-v" or $option ... HomePerlArrayCGIClassDataTypeDatabaseFileGUIHashLanguageBasicsNetworkRegularExpressionReportStatementStringSubroutineSystemFunctionsWin32XMLshift:defaultstoshifting@ARGV:SpecialVariables « LanguageBasics « PerlPerlLanguageBasicsSpecialVariablesshift:defaultstoshifting@ARGV #!/usr/bin/perl-w usestrict; subversion{ print"version\n"; } my$option=shift;#defaultstoshifting@ARGV version()if$optioneq"-v"or$optioneq"--version"; print"Hello,world.\n"; 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.104.Usingthe$.variable.105.Usingthe$;(dollarandsemicolon)variable.106.Usingthe@_toreferencetheparameter107.UsingtheDefaultVariable$_108.Usingthediamondoperatorwith@ARGV109.Usingtheifstatementtocheckthecommandlineparameters110.UsingthespecialPerlvariable$!inthemessagepassedtodie.111.Usingtrtoconvertallfilenamespassedintouppercase112.Verifythetotalnumberofthecommandlineparameter113.Workingwith$_usuallymakesprogrammingmucheasier,butmoreconfusingtotheuninitiated114.YoudisplaythecurrentlineofexecutioninaPerlscriptbyreferringtoitwiththe__LINE__token.115.YoudisplaythenameofthecurrentPerlpackagewith__PACKAGE__.116.Youdisplaythenameofthecurrentfilewiththe__FILE__token117.foreach(@_)118.foreachloopand$_119.ordie$!120.ordie$^E;121.print"Hello,$ENV{USER}!\n";122.print$INC{'English.pm'};123.print$];(Perlversionnumber)124.printoutallpmlibrarylocation125.printsouteachelementof@ARGVseparately126.time-$^T127.undef$/;



請為這篇文章評分?