in reply to unix to windows?

I updated tcgrep with a similar feature. It will expand wildcards into the ARGV array, in a way that works right under the platform, if it detects the need.

do_glob is passed the options hash, so it can check flags for overrides and globbing mode argument switch. Note the DOS-style quoting rules wrapper around the built-in glob abilities. This worked fine when I wrote it, but has a little problem now with the latest ActiveState build (concerning directories, I think) but I could override the rule on the command line so I've not gotten to the bottom of it yet.

—John

our $default_optG= 'none'; ################################### # This function added 19-Feb-2001 by John M. Dlugosz. # When should this script expand globs (wildcard characters) in the fi +le name arguments? # First idea is when the OS (via $^OS) is Windows or other non-Unix sy +stems. 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 u +pdated 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 c +alled, is what # remains in @ARGV. # This is abstracted into its own function in case it gets more comple +x, 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/Windo +ws/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 sl +ashes $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; }