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!

Argument Checker

Status
Not open for further replies.

iamberb

Programmer
Jul 14, 2005
15
DE
Hi,
Has someone written a smart and flexible argument check routine. One most boring code to write again and again is to check the arguments validity of arguments passed to some perl tools.
I am looking for some package which can handle argument checks dynamically.
Pass what arguments should exists and pass in the @ARGV to check them if valid or not.
Anyone having written something like that ?

brg Robert
 
Hi,
The GetOpt::Long looks quite nice for me.
But I wonder how to handle positioned parameters.
What u have is:
-tag (flag) found in getopt
-tag value (value) found in getopt
value1 value2 not found in getopt

So how to handle this via this package ?
I could not find positioned parameter handling.

brg Robert
 
Hi Barbie,

No I mean arguments like following examples.

mycopy filepath_value targetpath_value

So you path 2 parameters and you know from the position what value is what kind of arguments.

There are no tags for it.

So is there some way to check this kind of values with getopt or any other package ?

brg Robert

 
Can't you just check them directly - you don't need getopts for that...
Code:
...
die "Usage: $0 project prefix outfile" unless (@ARGV == 3);
for a crude example that expects 3 parameters, and issues a usage message if it doesn't have the right number.
 
Hi,

I can check everything with my own code.
But i was looking for a tool which is checking the arguments on a certain behavior.

1 thing is to check what flags are existing and get the value for value flags.

The other things is to check in which combination the are allowed to exists.

First part is covered by getopt but fnally I can not easily get the standalone values out.
As u can have some arguments which are JUST values and some are taged. In some case a combination of both.

copy -copyoption filevalue targetvalue

So would be great that i could state i have 1 flag and 2 values which are allowed and I can retrieve them no matter how the arguments are passed.
could be as well:

copy filevalue targetvalue -copyoption

I guess I will go your way and just check them as you said.

brg robert
 
From the link posted by Barbie
Usually programs take command line options as well as other arguments, for example, file names. It is good practice to always specify the options first, and the other arguments last. Getopt::Long will, however, allow the options and arguments to be mixed and 'filter out' all the options before passing the rest of the arguments to the program.
But it doesn't say how...

If that is the case, you could use Getopts to check all the switches and then just validate what's left in your code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top