Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: getting args without clobbering @ARGV

by ioannis (Vicar)
on May 11, 2006 at 19:59 UTC ( #548821=note: print w/ replies, xml ) Need Help??


in reply to getting args without clobbering @ARGV

While previous posts prop better suggestions, another way is to declare @ARGV with local in a block so it reclaims the old values when it exits the block. As shown bellow, add lines #7, #8, and 19 to the old code:

my $arg; my $argcount = 0; my $debug = 0; my $infile; #line 7 { #line 8 local @ARGV = @ARGV; while (@ARGV) { $arg = shift @ARGV; if ($arg =~ /-d/) { $debug = 1; } elsif ($argcount == 0) { $infile = $arg; } } #line 19 }


Comment on Re: getting args without clobbering @ARGV
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://548821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2015-07-04 15:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls