NAME

Tie::Hash::MultiValueOpts - Store multiple values per option

SYNOPSIS

use Getopt::Std               qw( getopts );
use Tie::Hash::MultiValueOpts ();

tie my %opts, 'Tie::Hash::MultiValueOpts';
$opts{ l } = [];
getopts( 'a:bl:', \%opts );

DESCRIPTION

The Getopt::Std core module exports the getopts() function that processes single-character options. If we use the two-argument form of getopts(), the second argument is a HASH reference \%opts that stores the processing result. Each hash key refers to a provided option and the corresponding hash value refers to the option-argument (or 1 if it is a flag).

If an option that requires an option-argument is provided multiple times, the last argument wins (implicit overwrite). Sometimes we want to treat an option (l for example) as a multi-value option. In this case we have to bind the %opts variable to the Tie::Hash::MultiValueOpts class and we have to set its initial value to an empty ARRAY reference. If the multi-value option is now provided multiple times, their values are stored in order in @{ $opts{ l } }.

SEE ALSO

AUTHOR

Sven Willenbuecher <sven.willenbuecher@gmx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by Sven Willenbuecher.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.