On 11-10-08 02:37 PM, Natxo Asenjo wrote:
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;

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'
         ];

%excl_ref has only one key 'test' and its value is an anonymous hash [ '1', '2', '3' ]

When you don't send the reference to Dumper(), it expands the hash to a list and dumps each item in the list.


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

"Make something worthwhile."  -- Dear Hunter

--
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