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

Re^2: how to deal with incorrect command line argument

by scripter87 (Novice)
on Oct 30, 2013 at 22:28 UTC ( [id://1060463]=note: print w/replies, xml ) Need Help??


in reply to Re: how to deal with incorrect command line argument
in thread how to deal with incorrect command line argument

Thanks my man, does the trick. May I ask a few questions on your solution though... I am going to comment it on your code and maybe you can correct me where I am wrong.
my @array; # this an array to store the good arguments for (@ARGV) { # for the argumets array if (-e) { # if the file exists push @array, $_;# push the file that exists onto the @array # why use $_ here? next; # what purpose has this } warn qq{"$_" doesn't exist!}; } @ARGV = @array;
I Appreciate the time you took to answer my question to man.

Replies are listed 'Best First'.
Re^3: how to deal with incorrect command line argument
by Kenosis (Priest) on Oct 30, 2013 at 22:37 UTC

    You're most welcome! Am glad it helped.

    You're commenting is correct. You asked, "why use $_ here?" Because Perls default scalar ($_) is implicitly used in the for loop that's iterating through the elements of @ARGV. Note, also, that Perl's default scalar is also implicitly used in the expression if (-e) { as that expression is equivalent to if (-e $_) {.

    The purpose of next is to get the next element of @ARGV, otherwise a warn would occur.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 08:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found