If I have a search string, such as:
decorated "blue widgets" "red widgets" sandy leaf.
What is the best way of splitting that string up, so that I have an array with the following data:
- decorated
- blue widgets
- red widgets
- sandy
- leaf
currently, I'm splitting the string with split(/ /) to get the individual words, then piecing together the quoted words
cheers
my $var = qq~decorated "blue widgets" "red widgets" sandy leaf.~;
$var =~ s/("[^\"]*")/unspacify($1)/ge;
my @array = split(/\s+/,$var);
s/\^//g for @array;
print map{"$_\n"} @array;
sub unspacify {
#replaces spaces within quoted words with ^
my $string = shift;
$string =~ s/\s/\^/g;
return($string);
}