This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Speed up csh_glob
[perl5.git] / ext / File-Glob / Glob.pm
index eead378..f9f0edd 100644 (file)
@@ -36,7 +36,7 @@ use feature 'switch';
 
 @EXPORT_OK   = (@{$EXPORT_TAGS{'glob'}}, 'csh_glob');
 
 
 @EXPORT_OK   = (@{$EXPORT_TAGS{'glob'}}, 'csh_glob');
 
-$VERSION = '1.10';
+$VERSION = '1.14';
 
 sub import {
     require Exporter;
 
 sub import {
     require Exporter;
@@ -77,22 +77,6 @@ my %entries;
 sub csh_glob {
     my $pat = shift;
     my $cxix = shift;
 sub csh_glob {
     my $pat = shift;
     my $cxix = shift;
-    my @pat;
-
-    # glob without args defaults to $_
-    $pat = $_ unless defined $pat;
-
-    # extract patterns
-    $pat =~ s/^\s+//;  # Protect against empty elements in
-    $pat =~ s/\s+$//;  # things like < *.c> and <*.c >.
-                       # These alone shouldn't trigger ParseWords.
-    if ($pat =~ /\s/) {
-        # XXX this is needed for compatibility with the csh
-       # implementation in Perl.  Need to support a flag
-       # to disable this behavior.
-       require Text::ParseWords;
-       @pat = Text::ParseWords::parse_line('\s+',0,$pat);
-    }
 
     # assume global context if not provided one
     $cxix = '_G_' unless defined $cxix;
 
     # assume global context if not provided one
     $cxix = '_G_' unless defined $cxix;
@@ -100,6 +84,27 @@ sub csh_glob {
 
     # if we're just beginning, do it all first
     if ($iter{$cxix} == 0) {
 
     # if we're just beginning, do it all first
     if ($iter{$cxix} == 0) {
+       my @pat;
+
+       # glob without args defaults to $_
+       $pat = $_ unless defined $pat;
+
+       # extract patterns
+       $pat =~ s/^\s+//;       # Protect against empty elements in
+                               # things like < *.c>, which alone
+                               # shouldn't trigger ParseWords.  Patterns
+                               # with a trailing space must be passed
+                               # to ParseWords, in case it is escaped,
+                               # as in glob('\ ').
+       if ($pat =~ /[\s"']/) {
+           # XXX this is needed for compatibility with the csh
+           # implementation in Perl.  Need to support a flag
+           # to disable this behavior.
+           require Text::ParseWords;
+           for (@pat = Text::ParseWords::parse_line('\s+',1,$pat)) {
+               s/^['"]// and chop;
+           }
+       }
        if (@pat) {
            $entries{$cxix} = [ map { doglob($_, $DEFAULT_FLAGS) } @pat ];
        }
        if (@pat) {
            $entries{$cxix} = [ map { doglob($_, $DEFAULT_FLAGS) } @pat ];
        }