Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: hmm - - - something has changed in perl (from 5.34 to 5.36

by Tux (Canon)
on Nov 24, 2022 at 10:12 UTC ( [id://11148350]=note: print w/replies, xml ) Need Help??


in reply to Re: hmm - - - something has changed in perl (from 5.34 to 5.36
in thread hmm - - - something has changed in perl (from 5.34 to 5.36

100% agree with this! And Getopt::Long is extremely easy:

use 5.026000; use warnings; use Getopt::Long; GetOptions ( "B|before=i" => \my $before, # An integer argument is required ) or die "User-friendly message\n");

And if you want -B without any argument to default to say 42, all you have to change is

GetOptions ( "B|before:42" => \my $before, # An integer argument is optional an +d defaults to 42 when -B used without arg ) or die "User-friendly message\n");

One step further: set a default, and also give a different default for -B without argument

GetOptions ( "B|before:42" => \(my $before = 2), ) or die "User-friendly message\n");

In the first two examples $before will have the value undef when the option -B is not given at all. In the last example the default will be 2.


Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-25 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found