use strict; use warnings; use Getopt::Long; use Data::Dumper; #------------------------------------------------------- sub parseArgs { my ($aRules, $aArgs) = @_; # version used with 5.8.8 expects arguments in @ARGV # the version in the 5.10 core has a function that can # read arguments from any array, not just @ARGV. local @ARGV = @$aArgs; Getopt::Long::GetOptions(my $hOpts={}, @$aRules); return $hOpts; } #------------------------------------------------------- my $aRules = [ 'name=s' #allow any string as value , 'val|v=i' #allow --val or -v, require number , 'list=s@{,}' #allow arbitrary lists of values ]; my $hParsed = parseArgs($aRules, \@ARGV); print Dumper($hParsed);