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; }

In reply to Globbing in Windows by John M. Dlugosz
in thread unix to windows? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.