in reply to Mimicking Unix shell quoting in Perl
use strict; use warnings; use Text::Balanced qw(extract_delimited); my $cmd = qq{perl g.pl arg1 'arg 2' "arg 3" "arg \\"4" arg5}; my @tokens; while(length($cmd)){ my $ext = extract_delimited($cmd); if (not defined $ext) { $cmd=~s/^\s*(\S+)\s*//; $ext=$1; } else { ####no delimiters # $ext=substr($ext,1,-1); } push @tokens,$ext; } print join "\n",@tokens;
|
|---|