hi,

I need to add a cli option to my script to push multiple values in a
hash. I have verified that using Getopt::Long this is possible, but
cannot get my head around dereferencing it.

This is a sample code:

==============================================================
use strict;
use warnings;
use Getopt::Long;

Getopt::Long::Configure( "no_ignore_case", "bundling" );

my ($checknow, $help, $revision, %excl_ref );
GetOptions(
    'c|checknow'          => \$checknow,
    'h|help|?'                => \$help,
    'V|version'              => \$revision,
    'e|exclude=s%'      => sub { push( @{$excl_ref{$_[1]}}, $_[2] ) },
);

use Data::Dumper;

print Dumper %excl_ref;
=============================================================

when I run this I get:
./kk.pl -e test=1 -e test=2 -e test=3
$VAR1 = 'test';
$VAR2 = [
          '1',
          '2',
          '3'
        ];

But I do not see how I can retrieve these values. I understand that in
Getopt::Long when we use a sub, the first argument $_[0] is the name
of the option, $_[1] in this case is the key and $_[2] is the value,
but I do not understand how I can dereference it, I am afraid.

Any help appreciated. TIA.
--
Groeten,
natxo

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to