our $default_optG= 'none'; ################################### # This function added 19-Feb-2001 by John M. Dlugosz. # When should this script expand globs (wildcard characters) in the file name arguments? # First idea is when the OS (via $^OS) is Windows or other non-Unix systems. But, what # if you're running a globbing shell anyway? I need to know the shell that invoked Perl (if any), # not the OS. # I abstracted out the logic into this function, so it may easily be updated or customized. sub shall_I_glob (%) { my $opt= shift; if (exists $opt->{G}) { return $opt->{G} ne "none"; } my $shell= $ENV{COMSPEC}; if (defined $shell && $^O =~ /^MS/i) { $default_optG= 'qDOS'; # if this exists, assume an OS with a DOS lineage. # List those I know about. Others will add to this list as the need arises. return 1 if $shell =~ /4nt.exe$/i; # return true for shells that don't glob arguments. return 1 if $shell =~ /4dos.exe$/i; return 1 if $shell =~ /cmd.exe$/i; return 1 if $shell =~ /command.com$/i; return undef if $shell =~ /bash.exe$/i; # return false for shells that glob before running program } # ... try other ways to get $shell here. ... return undef; # don't do anything (the behavior we always had). } ################################### # This function added 19-Feb-2001 by John M. Dlugosz. # This will 'glob' the filename arguments, which at the time this is called, is what # remains in @ARGV. # This is abstracted into its own function in case it gets more complex, such as # special quoting rules. sub do_glob (%) { my $opt= shift; my $globsub= undef; my $optG= $opt->{G} || $default_optG; my $quoteflag= ($optG =~ /^q/); if ($optG =~ /DOS$/) { # Use DosGlob, not core glob require File::DosGlob; $globsub= \&File::DosGlob::glob; } # could have others (e.g. regex glob, 4DOS-style glob) added HERE. my @result; foreach my $fname (@ARGV) { if ($quoteflag) { # glob() doesn't like the stuff a DOS/Windows/NT user puts on # the command line, especially if using command-completion or other tools which # will always use backslash not giving you the oppertunity to type the forward slash instead. # This was found to work on both glob() forms and give the expected results. $fname =~ s/\\/\//g; # changes backslashes to forward slashes $fname= qq("$fname"); # put whole thing in quotes } push @result, $globsub ? $globsub->($fname) : glob($fname); } if ($quoteflag) { # restore canonical path separator foreach (@result) { s[/][\\]g }; } @ARGV= @result; }