Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2023-02-03 13:32 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (26 votes). Check out past polls.