in reply to Creating a Hash from Two Arrays

well, aside from looking at Getopt::Std, you can do something like this:
my %opts; foreach (@switches) { # init the array for each $opts{$_} = []; } my $curswitch = ''; foreach (@values) { $curswitch = $_ and next if exists $opts{$_}; push @{$opts{$curswitch}}, $_; }
Untested but should give you an idea. You'll end up with a hash or arrays keyed by the different switches.

-- Dan

Replies are listed 'Best First'.
Re^2: Creating a Hash from Two Arrays
by Aristotle (Chancellor) on Sep 18, 2002 at 19:55 UTC
    Some hints on style: your initialization code is rather redundant. This will do the same job:
    my %opts; @opts{@switches} = ([]) x @switches;
    However, due to autovivification you needn't even go through the trouble of assigning those empty lists beforehand. The following will do.
    my %opts; @opts{@switches} = ();
    End of style hints. The following is a slight optimization of the work loop, including switch checking:
    my $curswitch; for (@values) { exists $opts{$_} ? $curswitch = \$opts{$_}, next : die "Unknown switch: $_\n" if /^-/; defined $curswitch or die "Not a switch: $_\n"; push @$curswitch, $_; }

    Makeshifts last the longest.