On Sat, Oct 8, 2011 at 14:37, Natxo Asenjo <[email protected]> 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.
[ snip ]
> 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 is a hash where the keys are on the left hand side of the
'=' and the values are arrayrefs of the things on the right hand side
of the '='.
This will be more clear if you pass Data::Dumper a reference; that
will get you output that looks like this:
$ ~/try.pl -e test=1 -e test=2 -e test=3
$VAR1 = {
'test' => [
'1',
'2',
'3'
]
};
You could access those -- depending on what you're trying to do -- like so:
foreach my $key ( keys %excl_ref ) {
foreach my $value ( @{ $excl_ref{$key} ) {
print "$key = $value\n";
}
}
Hope this helps.
chrs,
john.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/