package Text::ParseWords;
use vars qw($VERSION @ISA @EXPORT $PERL_SINGLE_QUOTE);
-$VERSION = "3.24";
+$VERSION = "3.25";
require 5.000;
sub shellwords {
- my(@lines) = @_;
- $lines[$#lines] =~ s/\s+$//;
- return(quotewords('\s+', 0, @lines));
+ my (@lines) = @_;
+ my @allwords;
+
+ foreach my $line (@lines) {
+ $line =~ s/^\s+//;
+ my @words = parse_line('\s+', 0, $line);
+ pop @words if (@words and !defined $words[-1]);
+ return() unless (@words || !length($line));
+ push(@allwords, @words);
+ }
+ return(@allwords);
}
use warnings;
use Text::ParseWords;
-print "1..22\n";
+print "1..23\n";
@words = shellwords(qq(foo "bar quiz" zoo));
print "not " if $words[0] ne 'foo';
$result = join('|', shellwords($string));
print "not " unless $result eq "";
print "ok 22\n";
+
+# make sure shellwords strips out leading whitespace and trailng undefs
+# from parse_line, so it's behavior is more like /bin/sh
+$result = join('|', shellwords(" aa \\ \\ bb ", " \\ ", "cc dd ee\\ "));
+print "not " unless $result eq "aa| | bb| |cc|dd|ee ";
+print "ok 23\n";