Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ARGV question 2

Status
Not open for further replies.

goliath

MIS
Aug 18, 1999
62
US
Hello,

I think I'm getting close to the solution...

What I'd like to do is be able to pass to the perl program either 1, 2 or no arguements and of the two passed maybe allow them to be in either order....

Example:

Perl userquery.pl myname -v
or
Perl userquery.pl -v myname

-v for verbose

if they dont pass a username, I will ask for one in the script. This means they could just do:

perl userquery.pl -v

not sure which to persue so far, something using a while @ARGV or using SHIFT...

I'll keep working on it, thanks for any help!

 
I think this is one of those times where there is more than one way to do it. Here is one possibility
Code:
(my $name = join ' ', @ARGV) =~ s/\s*(\-v)\s*//;
my $verbose = defined $1 ? 1 : 0;
You just need to test $name to see if it is the null string and then prompt the user if it is.

jaa
 
You might try looking at the Getopt::Std module, or the Getopt::Long module - read the perldocs on these modules that come included with Perl by doing

perldoc Getopt::Std

or

perldoc Getopt::Long

at a command prompt.

HTH. Hardy Merrill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top