in reply to Re: Creating a Hash from Two Arrays
in thread Creating a Hash from Two Arrays
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} = ([]) x @switches;
End of style hints. The following is a slight optimization of the work loop, including switch checking:my %opts; @opts{@switches} = ();
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.
|
|---|