Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Storing multiple arguments in a data structure that allows for future expansion

by Moron (Curate)
on May 02, 2007 at 08:57 UTC ( #613139=note: print w/replies, xml ) Need Help??


in reply to Storing multiple arguments in a data structure that allows for future expansion

I use a hash for the options whose keys are option letters and whose values can be either a scalar for a single or empty value or an array reference for multiple values, e.g.:
use Getopt::Std; my %opt; getopt('abc',\%opt); Multivalued(\%opt); #... sub Multivalued { # convert lists to array refs. my $href = shift; while( my ($k, $v ) = each %$href ) { my @anon = split /\,/, $v or next; $href -> { $k } = \@anon; } }
And to iterate the combinations of the arrays, see Math::Combinatorics.

Update: and if you have to support protected commas in quotes, instead of just splitting, parse with something like Text::Csv::Simple

__________________________________________________________________________________

^M Free your mind!

  • Comment on Re: Storing multiple arguments in a data structure that allows for future expansion
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://613139]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2021-08-01 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (8 votes). Check out past polls.

    Notices?