/(\w+)/g gets the command as well and only the args are wanted, so it would need to be
my @args = $s =~ / (\w+)/g; shift @args; also, my VAR if TEST; is deprecated IIRC and slated to be removed soon (as it's behavior is surprising). It would probably be better to say my @args = $s =~ /^\w+\s/ && $s =~ /(?:\s+(\w+))/g; or (if you don't like using && like that) my @args = $s =~ /^\w+\s/ ? $s =~ /(?:\s+(\w+))/g : (); On Wed, Mar 1, 2017 at 9:34 AM X Dungeness <[email protected]> wrote: > On Wed, Mar 1, 2017 at 2:52 AM, Chas. Owens <[email protected]> wrote: > > Sadly, Perl will only capture the last match of capture with a > qualifier, so > > that just won't work. The split function really is the simplest and most > > elegant solution for this sort of problem (you have a string with a > > delimiter and you want the pieces). All of that said, if you are > willing to > > modify the regex you can say > > > > my $s = "command arg1 arg2 arg3 arg4"; > > my @args = $s =~ /(?:\s+(\w+))/g; > > > > Hm, I'd write it as: > my @args = $s =~ / (\w+)/g; > > or, if the command check isn't too inelegant: > > my @args = $s =~ / (\w+)/g if $str =~ /^command\s/; > > > > for my $arg (@args) { > > print "$arg\n"; > > } > > > > However, this does not allow you to check the command is correct. > > >
