Command line argument variable @ARGV in Perl

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

It chops off the first two arguments from @ARGV and puts them in $var1 and $var2. Personally I would have written it as: $var1 = shift @ARGV ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam StackOverflowforTeamsismovingtoitsowndomain!Whenthemigrationiscomplete,youwillaccessyourTeamsatstackoverflowteams.com,andtheywillnolongerappearintheleftsidebaronstackoverflow.com. Checkyouremailforupdates. Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams Commandlineargumentvariable@ARGVinPerl AskQuestion Asked 7yearsago Modified 7yearsago Viewed 1ktimes 3 New!Savequestionsoranswersandorganizeyourfavoritecontent.Learnmore. Iamblankwithperl.IhaveatasktoconvertscriptfromPerltoPowerShell.Sorequestingyoutobekindwithyouranswers. IreadaboutcommandlineargumentofPerl@ARGV.IunderstandthatatthetimeofperlscriptexecutionanyargumentispassedwillcapturedbythisspecialarrayvariableinPerl.Wecanread@ARGVandassignvaluestoscalarvariableusingbelow ($var1,$var2)=@ARGV; Ineedtounderstandwhatbelowstatementisdoing ($var1,$var2,@ARGV)=@ARGV; InmyperlscriptwehaveIfconditiononvaluesin@ARGVandbasedon@ARGVvaluesrespectivesubroutineisgettingcalled. Aspermyunderstandingifwehavemorethantwovaluesin@ARGVthenonleftsideinparenthesisstatementischangingvaluesofARGV/usedtorewrite@ARGVwithremainingValues? Pleasehelpmetounderstandthiswithasimpleexample. Thanks Ravi perlcommandargumentslineargv Share Improvethisquestion Follow askedSep30,2015at10:50 RaviBhavsarRaviBhavsar 3977bronzebadges Addacomment  |  1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 6 Itchopsoffthefirsttwoargumentsfrom@ARGVandputsthemin$var1and$var2. PersonallyIwouldhavewrittenitas: $var1=shift@ARGV; $var2=shift@ARGV; Butitisamatteroftaste. Share Improvethisanswer Follow answeredSep30,2015at10:54 OleTangeOleTange 30.3k55goldbadges8282silverbadges9797bronzebadges 2 7 Iprobablywouldn'thavedoneeventhatmy($first,$second,@everything_else)=@ARGV;ismoremysortofthing:) – Sobrique Sep30,2015at11:11 1 @SobriqueTheremaybeacalltoGetOptionslaterinthescript,whichwouldrequirethemodificationof@ARGV. – BradGilbert Oct2,2015at23:20 Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedperlcommandargumentslineargvoraskyourownquestion. TheOverflowBlog IntroducingtheOverflowOfflineproject Hehelpedbuild.NETandVSCode—Now’sheworkingonWeb3(Ep.499) FeaturedonMeta The2022Community-a-thonhasbegun! Mobileappinfrastructurebeingdecommissioned CollectivesUpdate:RecognizedMembers,Articles,andGitLab The[script]tagisbeingburninated StagingGroundWorkflow:CannedComments Related 5819 HowdoIexecuteaprogramorcallasystemcommand? 944 What'sthedifferencebetweenanargumentandaparameter? 2432 HowdoIparsecommandlineargumentsinBash? 758 WhichexceptionshouldIraiseonbad/illegalargumentcombinationsinPython? 749 HowtofixalocalesettingwarningfromPerl 640 Whatdoesintargc,char*argv[]mean? 4969 Reference—WhatdoesthissymbolmeaninPHP? 2842 HowdoIpasscommandlineargumentstoaNode.jsprogram? 3 Findingpipeandredirectsinperl@ARGV HotNetworkQuestions WouldaTrump-nominatedSupremeCourtjusticebeexpectedtorecusethemselvesfromaTrumpcase? CanyoubetterexplainthePF1efeatFastLearner(Human)? Mylibrarymembershipnumber Whataredisadvantagesofaerodropbars? HowcanIprintoutthefirstlineofallthefilesthatmatchcertain"find"criteria? HowdoyoudescribesomeoneasashapeshifterinLatin? Whatwouldan"excessivelysober"dwarflooklikeiftheyneedalcoholtofunction? Whyaretheredollaramountslistednearthecopyrightinformationforjournalarticles? Whattodoafterapuremathacademicpath? HowcanApophishaveason? UnderwhatauthoritycantheUSmakefederalreservenoteslegaltender? IsGoogleStreetViewcoverageinGermanyexpectedtoincrease? Robbersinastandoff Whatisanaxiomatizationoftheequality-freetheoryofantisymmetricrelations? CanIpublishmythesisonlineandgetpaid? Shouldmy240velectricstovebegroundedtotheneutrallikethis? Changingnumberformatsinstrings Istriplebranchingnecessaryinmakingasyntaxtreefor'thegirlintheroomwavedtome'? WhywasThor'shammerneverusedagain? HowcanIconnectTikZnodeswithmultiple-cornerlines? WhyisthePassivevoiceof"einladen"usedwith"sein"andnotwerden? Element-wisecomparisonsofsortedsubsetsofrandomnumbersyieldnonrandomresults Isthereawayasocietycouldproducetanksascheaplyascars? QGISdelimitedtextlayerisnotvisible morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-perl Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?