This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make the "back to top" links optional
[perl5.git] / lib / shellwords.pl
index 168991f..1c45a5a 100644 (file)
@@ -1,12 +1,12 @@
-#; shellwords.pl
-#;
-#; Usage:
-#;     require 'shellwords.pl';
-#;     @words = &shellwords($line);
-#;     or
-#;     @words = &shellwords(@lines);
-#;     or
-#;     @words = &shellwords;           # defaults to $_ (and clobbers it)
+;# shellwords.pl
+;#
+;# Usage:
+;#     require 'shellwords.pl';
+;#     @words = &shellwords($line);
+;#     or
+;#     @words = &shellwords(@lines);
+;#     or
+;#     @words = &shellwords;           # defaults to $_ (and clobbers it)
 
 sub shellwords {
     package shellwords;
@@ -17,12 +17,18 @@ sub shellwords {
     while ($_ ne '') {
        $field = '';
        for (;;) {
-           if (s/^"(([^"\\]+|\\[\\"])*)"//) {
+           if (s/^"(([^"\\]|\\.)*)"//) {
                ($snippet = $1) =~ s#\\(.)#$1#g;
            }
-           elsif (s/^'(([^'\\]+|\\[\\'])*)'//) {
+           elsif (/^"/) {
+               die "Unmatched double quote: $_\n";
+           }
+           elsif (s/^'(([^'\\]|\\.)*)'//) {
                ($snippet = $1) =~ s#\\(.)#$1#g;
            }
+           elsif (/^'/) {
+               die "Unmatched single quote: $_\n";
+           }
            elsif (s/^\\(.)//) {
                $snippet = $1;
            }