in reply to Parsing command line
Here's the function:$cmdline = join(' ',@ARGV); parsetoargv($cmdline);
Now your @ARGV is ready for GetOptions.sub parsetoargv { my ($cmdline, $idx) = (shift, 0); @ARGV = (); { $cmdline =~ m{ \G\ }gcx && do {redo}; # Eat a space $cmdline =~ m{ \G" }gcx && do { # Start a quot +ed-string $cmdline =~ m{ \G(.*?)(?<!\\)" }gcx && do { # Match up t +o the next unescaped quote ($ARGV[$idx++] = $1) =~ s/\\"/"/g; # And put +it in ARGV, removing escaping slashes }; redo }; $cmdline =~ m{ \G(.*?)(?="|\ |$) }gcx && do { # Match up to +just before the next quote, space, or end-of-line $ARGV[$idx++] = $1 if ($1 ne ''); redo # And put it +in ARGV if it isn't empty }; } }
|
|---|