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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter checking

Status
Not open for further replies.

columb

IS-IT--Management
Joined
Feb 5, 2004
Messages
1,231
Location
EU
I'm using Getopts::Std to parse command line parameters. The -n flag needs to take a numeric value. The relevant bits of code are
Code:
my %opts;
getopts 'lfh:?tm:n:', \%opts or print_usage;
defined $opts{'?'} and print_usage;

( defined $opts{'n'} ) && ( ! $opts{'n'} =~ /^\d+$/ ) and print_usage;
Firstly, why doesn't this work? And secondly, there must be a better check for $opts{'n'} being numeric. All suggestions welcome.

Thanks

Ceci n'est pas une signature
Columb Healy
 
($opts{'n'} !~ /[0-9]/)

"$opts{n} doesn't contain numbers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top