I got this code below to work as I need, but would like to know if there's a better way of doing this without quotes.
myScript.pl --filter 'key1 foo bar' --filter 'key2 baz qux'
#!/usr/local/bin/perl5.8.8
use warnings;
use strict;
use Getopt::Long;
use Data::Dumper;
my %filter;
GetOptions("filter=s" => sub { my @args = split(/\s/, $_[1]); $filter{$args[0]}{value1} = $args[1]; $filter{$args[0]}{value2} = $args[2]; });
print Dumper %filter;
I get a satisfactory output:
$VAR1 = 'key2';
$VAR2 = {
'value1' => 'baz',
'value2' => 'qux'
};
$VAR3 = 'key1';
$VAR4 = {
'value1' => 'foo',
'value2' => 'bar'
};
However, I would like to use it like this, without quotes:
myScript.pl --filter key1 foo bar --filter key2 baz qux --other_option ...
key1 and key2 are hash keys here and will be unique.
Any ideas/suggestions?