use Text::ParseWords;
@words = quotewords($delim, $keep, @lines);
quotewords()
accepts a delimiter (which can be a regular expression)
and a list of lines, and then breaks those lines up into a list of
delimiter-separated words. It ignores delimiters that appear inside
single or double quotes.
The
$keep
argument is a Boolean flag. If it is false, then quotes
are removed from the list of words returned by
quotewords()
;
otherwise, quotes are retained.
The value of
$keep
also affects the interpretation of backslashes.
If
$keep
is true, then backslashes are fully preserved in the
returned list of words. Otherwise, a single backslash disappears and a
double backslash is returned as a single backslash. (Be aware, however,
that, regardless of the value of
$keep
, a single backslash occurring
within quotes causes a Perl syntax error - presumably a bug.)