I'm using Getopt::Lucid to process CLO and I've run into an interesting and unexpected problem. The following code:
push @clo_spec, map { Switch($_) } qw(-c -m -s -p),
map { Switch($_) } qw(--help --man --usage --version),
map { Switch($_) } qw(--debug --verbose),
map { Param($_) } keys %$rc_spec_ref
;
my $clo_o = Getopt::Lucid->getopt(\@clo_spec);
generates the following error:
'Getopt::Lucid::Spec=HASH(0x9383847)' is not a valid option name/alias
Now, Getopt::Lucid is configured by quoting an string expression representing valid options and then passing those strings to one of six subroutines which return blessed hashes. Each subroutine represents a type of option; switch, counter, parameter, list or key-pair.
The interesting part is that if any three map expressions are removed,
push @clo_spec, #map { Switch($_) } qw(-c -m -s -p),
map { Switch($_) } qw(--help --man --usage --version),
#map { Switch($_) } qw(--debug --verbose),
#map { Param($_) } keys %$rc_spec_ref
;
then everything works fine. The even more interesting part is that if you encase each map expression in parentheses, everything also works fine:
push @clo_spec, (map { Switch($_) } qw(-c -m -s -p)),
(map { Switch($_) } qw(--help --man --usage --version)),
(map { Switch($_) } qw(--debug --verbose)),
(map { Param($_) } keys %$rc_spec_ref)
;
The above leads me to believe that this problem isn't related to a bug in Getopt::Lucid. Also, I considered the above fix after looking at the map function's reference which mentions that sometimes map can get confused with commas. Perl will flatten embedded lists, and the surrounding parentheses seem to have the effect of delineating each map expression, but I really don't understand what's going on.
Can someone please explain?