Most of your answer has been answered. As for having to use tr//, you can use m//:
++$counted_quotes while $string =~ /"/g;
Not sure which one you'd want though, the tr// or that longer m//. One thing that I noticed immediately about your script is a lack of the strict pragma. You might want to add that :)
Update: I actually posted a reply to answer this, only to find I replied to a different node lol. Anyway, to copy it over (okay, I modified the regex in this version to rid of the terrible horrible abomination (I mean the ".*?"):
my $string = 'first-item "second item" ' . 'third-item "fourth item"'; my %items; push @{$items{ $1 =~ /"/ ? 'quoted' : 'unquoted' }}, $1 while $string =~ /("[^"]+"|\S+)/g; print 'Quoted: ', join(', ', @{$items{'quoted'}}), "\n"; print 'Unquoted: ', join(', ', @{$items{'unquoted'}}), "\n";
Credits: theorbtwo for "terrible horrible abomination", which he just posted in the CB, saying he got to use it in a sentence. I couldn't let him be th eonly one to use it :)
If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.
In reply to Re: separated quoted stings from unquoted strings
by Coruscate
in thread separated quoted stings from unquoted strings
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |