in reply to Re: Parsing a command-line string into an array
in thread Parsing a command-line string into an array
hmmm, thanks but that opens a different can of worms. I would prefer to rely on a module than string-splitting.
Perhaps I can do something like this way-round-about way:
use Data::Roundtrip qw/json2perl/; use File::Temp; use strict; use warnings; my $cmdlinestr = <<EOC; -x 123 -y 'some val' EOC my ($fh, $fn) = File::Temp::tempfile(); print $fh 'use Data::Roundtrip qw/perl2json/; print perl2json(\@ARGV)' +; close $fh; my $ret = `$^X ${fn} ${cmdlinestr}`; my $args = json2perl($ret); print join("\n", @$args)."\n";
Basically, rely on shell/perl to split the string into @ARGV, by spawning a basic perl script with the cmdline, get a json back and have that back to perl array. A lot can go wrong in this as well.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Parsing a command-line string into an array
by ikegami (Patriarch) on Dec 23, 2023 at 05:50 UTC |