NAME
getopt-long-sample-implicit-dest-hash-storage - Example of Getopt::Long usage with some implicit destinations
VERSION
This document describes version 0.001 of getopt-long-sample-implicit-dest-hash-storage (from Perl distribution App-GetoptLongExamples), released on 2019-01-30.
SYNOPSIS
DESCRIPTION
When getting options with Getopt::Long's GetOptions, one usually specifies a destination for each option specification:
GetOptions(
'foo=s' => \$foo,
'bar=s' => \@bar,
'help' => sub { ... },
);
But Getopt::Long allows not specifying these destinations. When the first argument is a reference to a hash ("hash storage mode") then the hash (with the option name as the key being looked up) will be consulted for the destination and if no such destination exist, the hash key will be set:
my %opts = (
bar => \@bar,
);
GetOptions(
\%opts,
'foo=s', # will set $opts{foo}
'bar=s', # will push to @bar
'help' => sub { ... },
);
When the first argument is not a hashref ("classic mode"), the corresponding $opt_OPTIONNAME
will be set, without regard of destination types.
GetOptions(
'foo=s', # will set $opt_foo to option value, regardless of current content of $opt_foo
'bar=s', # will set $opt_bar to option value, regardless of current content of $opt_bar
'help' => sub { ... },
);
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-GetoptLongExamples.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-GetoptLongExamples.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-GetoptLongExamples
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.