vchtyp=I jrnltyp=D lexwhere="'in('DIS', 'DIM', 'DIR')'" title="'this is a title'" #### $hash{vchtyp} = 'I' $hash{jrnltyp = 'D'; $hash{lexwhere} = "'in('DIS', 'DIM', 'DIR')'"; $hash{title} = "'this is a test'"; #### sub parseArgs { my (@args) = @_; my @chars = split(// , join(' ', @args)); my %params = (); my $label = ''; my $value = ''; my $inLabel = 0; my $inValue = 0; my $doubleQuotes = 0; my $singleQuotes = 0; my $isSpace = 0; my $isEquals = 0; my $isDoubleQuote = 0; my $isSingleQuote = 0; for my $char (@chars) { $isSpace = $char =~ /\s/; $isEquals = $char eq '='; $isDoubleQuote = $char eq '"'; $isSingleQuote = $char eq "'"; if ($inLabel) { if ($isEquals) { $inLabel = 0; $inValue = 1; } else { $label .= $char; } } elsif ($inValue) { $doubleQuotes++ if $isDoubleQuote; $singleQuotes++ if $isSingleQuote; if ($isSpace) { if (($singleQuotes % 2) == 0 && ($doubleQuotes % 2) == 0) { $inValue = 0; $params{$label} = $value; $label = ''; $value = ''; } else { $value .= $char; } } else { $value .= $char; } } elsif (!$isSpace) { $inLabel = 1; $label .= $char; } } if ($inValue && $label && $value) { $params{$label} = $value; } return %params; }