[Israel.pm] quick help please on parameter parsing
Yuval Yaari
yuval at windax.com
Tue Oct 19 10:47:18 PDT 2004
Yuval Yaari wrote:
> Prager, Mark wrote:
>
>> Hi -
>> I want to pass a parameter for timenow to a perl script -
>> so the parameter can be either
>> now or
>> now+NoOfMinutes
>>
>> How can I parse this easily in perl to get the no of minutes ( zero
>> or more ) ?
>>
> What's wrong with @ARGV or Getopt::Std and some basic regex?
> $ARGV[0] =~ m/now\+(\d+)$/;
A co-worker (you know who you are :)) told me that I was too aggressive,
and he's probably right. Sorry...
Let's assume you're using $ARGV[0] (but consider Getopt::Std):
if ($ARGV[0] =~ m/^now\+(\d+)$/i) {
# do whatever you want with $1, which will hold the number of minutes
} elsif (lc($ARGV[0]) eq 'now') {
# it is 'now', but without number of minutes
} else {
# give some error because the user didn't specify now or now+num
}
Again, I'm sorry.
--Yuval
More information about the Perl
mailing list