use strict; use warnings; use Getopt::Long; # fake populate ARGV my $sLine= < \@aCmdLineOpts); my $hCmdline = makeKeyValuePairsIntoHoA(\@aCmdLineOpts); # see results foreach my $k (sort keys %$hCmdline) { my $v = $hCmdline->{$k}; print "$k:<@$v>\n"; } # ==================================================== # subroutine for making key-value pairs into an HoA # ==================================================== sub makeKeyValuePairsIntoHoA { my ($aValues) = @_; # consolidate arguments so that all the # values belonging to REG1= are in a single # comma delimited list without spaces. my $sAllInOne = join(' ', @$aValues); $sAllInOne =~ s/\s*,\s*/,/g; # split into key-value pairs on whitespace my @aKeyValuePairs = split(/\s+/, $sAllInOne); my %hKeyValuePairs = map { my ($k,$v) = /(\w+)+=(.*)/; $k => [ split(/,/, $v) ] } @aKeyValuePairs; return \%hKeyValuePairs; }