Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^3: Range in Getopt

by james2vegas (Chaplain)
on Oct 03, 2012 at 18:34 UTC ( #997116=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Range in Getopt
in thread Range in Getopt

That is because while the d option's value is required, the d option itself is not, check the definedness of $_debug afterwards:

use Getopt::Long; my $_debug; GetOptions('d=i' => sub { $_debug = $_[1]; ($_debug > 0 && $_debug <= 4) or die "Invalid Debug Level ($_d +ebug)" } ) or exit 1; die "Debug Level is required" unless defined $_debug; warn "Debug Level is $_debug\n";

or set a default value before GetOptions:

use Getopt::Long; my $_debug = 0; GetOptions('d=i' => sub { $_debug = $_[1]; ($_debug > 0 && $_debug <= 4) or die "Invalid Debug Level ($_d +ebug)" } ) or exit 1; warn "Debug Level is $_debug\n";

Comment on Re^3: Range in Getopt
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997116]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2015-11-28 06:30 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (739 votes), past polls