fork download
  1. use Data::Dumper;
  2. $_ = 'command1 --max-size=2M a=ignore =ignore --switch --type="some value" --x= --z=1';
  3. my %args;
  4. while (/((?<=\s--)[a-z\d-]+)(?:="?|(?=\s))((?<![="])|(?<=")[^"]*(?=")|(?<==)(?!")\S*(?!"))"?(?=\s|$)/ig) {
  5. $args->{$1} = $2;
  6. }
  7. print Dumper($args);
Success #stdin #stdout 0.01s 5160KB
stdin
Standard input is empty
stdout
$VAR1 = {
          'switch' => '',
          'x' => '',
          'type' => 'some value',
          'z' => '1',
          'max-size' => '2M'
        };