c64whiz has asked for the wisdom of the Perl Monks concerning the following question:
I want to have Getopt::Std parse a "command line" for me, but the "command line" is coming from STDIN. I've done a simple "split /\s+/" to @ARGV, but that doesn't account for parameters with spaces surrounded by quotes:
use Getopt::Std; ## This works in general $cmdline = '-a b -c d'; @ARGV = split /\s+/, $cmdline; getopts( "a:c:" ); ### ...but this obviously fails: $cmdline = '-a "hello world" -b "some \"text\""';
The quoting and escaping is typically done by the *shell*. Any ideas to turn a scalar into an array for @ARGV? Using modules is OK provided they're part of the standard Perl distro; adding modules is not an option. Google's not being helpful.
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scalar to @ARGV for Getopt::Std
by haukex (Archbishop) on May 19, 2016 at 07:19 UTC | |
by oiskuu (Hermit) on May 21, 2016 at 00:51 UTC | |
|
Re: Scalar to @ARGV for Getopt::Std
by NetWallah (Canon) on May 19, 2016 at 04:53 UTC | |
|
Re: Scalar to @ARGV for Getopt::Std
by afoken (Chancellor) on May 19, 2016 at 06:08 UTC |