why use two passes? Give GetOptions a sub to call instead.
use Getopt::Long; my (@foos, @bars, @bazen, @quuxi); GetOptions ( 'foos=s' => sub { shift; push @foos, split /,/, @_; }, 'bars=s' => sub { shift; push @bars, split /,/, @_; }, 'bazen=s' => sub { shift; push @bazen, split /,/, @_; }, 'quuxi=s' => sub { shift; push @quuxi, split /,/, @_; }, );
of course, since your option names exactly match your arrays, something like this should work...
use Getopt::Long; my (@foos, @bars, @bazen, @quuxi); sub setter { no strict refs; push @{shift}, split /,/, @_; } GetOptions ( 'foos=s' => \setter, 'bars=s' => \setter, 'bazen=s' => \setter, 'quuxi=s' => \setter, );
but at that point you should just use...
use Getopt::Long; my %opts; sub setter { push @{$opts{shift}}, split /,/, @_; } GetOptions ( 'foos=s' => \setter, 'bars=s' => \setter, 'bazen=s' => \setter, 'quuxi=s' => \setter, );
(All of that is completely untested ... I'm sure I have some syntax typos).
Update: Yeah, What Roy said....
In reply to Re: Getting Sparse - Taming Multivalued Options in Getopt::Long
by hossman
in thread Getting Sparse - Taming Multivalued Options in Getopt::Long
by Zaxo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |