blink has asked for the wisdom of the Perl Monks concerning the following question:
myprog.pl -h <host> -d DD/MM/YYYY ] HH:MM:SS -e DD/MM/YYYY HH:MM:SS
This code will only capture DD/MM/YYYY, while ignoring HH:MM:SS as well as the entire argument to -e
#!/usr/local/bin/perl -w use strict; use Getopt::Std; getopts('c:d:e:h:'); our ($opt_c, $opt_d, $opt_e, $opt_h); # check our switch values if ($opt_h) { &help; } if ($opt_c) { my $client = $opt_c; } #else { &help; } print "d = $opt_d\ne = $opt_e\n"; &help unless ( ($opt_d, $opt_e) =~ m/(\d{2})\/(\d{2})\/(\d{4})(.*?)$/ + ); sub help { print <<HELP; usage: $0 -c <client> -d <begin date> [time] -e <end date> [time] Date must be in the format "DD/MM/YYYY", i.e., 09/04/2002. Time is optional. If it was included in the email you received from se +curity, then enter it. Time must be entered as "HH:MM:SS". example: $0 -c eman -d 09/01/2002 04:00:00 -e 09/04/2002 23:59:59 HELP exit 1; }
Running this code snippet produces the following output:
Does anyone have any ideas as to how to work around this?Useless use of a variable in void context at ./tape-pull.pl line 18. Use of uninitialized value in concatenation (.) or string at ./tape-pu +ll.pl line 16. d = 09/01/2002 e = Use of uninitialized value in pattern match (m//) at ./tape-pull.pl li +ne 18. usage: ./tape-pull.pl -c <client> -d <begin date> [time] -e <end date> + [time] Date must be in the format "DD/MM/YYYY", i.e., 09/04/2002. Time is optional. If it was included in the email you received from se +curity, then enter it. Time must be entered as "HH:MM:SS". example: ./tape-pull.pl -c eman -d 09/01/2002 04:00:00 -e 09/04/2002 2 +3:59:59
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using multiple args per switch with Getopts::Std
by kschwab (Vicar) on Aug 28, 2002 at 02:51 UTC | |
by blink (Scribe) on Aug 28, 2002 at 10:20 UTC | |
|
Re: Using multiple args per switch with Getopts::Std
by tommyw (Hermit) on Aug 28, 2002 at 10:56 UTC |