Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 ( #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? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-06-08 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (29 votes). Check out past polls.

    Notices?