in reply to Getting Sparse - Taming Multivalued Options in Getopt::Long
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....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting Sparse - Taming Multivalued Options in Getopt::Long
by Roy Johnson (Monsignor) on Jun 06, 2004 at 23:39 UTC | |
|
Re: Getting Sparse - Taming Multivalued Options in Getopt::Long
by Abigail-II (Bishop) on Jun 07, 2004 at 08:58 UTC |