perlwin32 - Perl under Win32

Extracted from ActivePerl documentation, section perlwin32


Command-line Wildcard Expansion
The default command shells on DOS descendant operating systems (such as they are) usually do not expand wildcard arguments supplied to programs. They consider it the application's job to handle that. This is commonly achieved by linking the application (in our case, perl) with startup code that the C runtime libraries usually provide. However, doing that results in incompatible perl versions (since the behavior of the argv expansion code differs depending on the compiler, and it is even buggy on some compilers). Besides, it may be a source of frustration if you use such a perl binary with an alternate shell that *does* expand wildcards.

Instead, the following solution works rather well. The nice things about it are 1) you can start using it right away; 2) it is more powerful, because it will do the right thing with a pattern like */*/*.c; 3) you can decide whether you do/don't want to use it; and 4) you can extend the method to add any customizations (or even entirely different kinds of wildcard expansion).

        C:\> copy con c:\perl\lib\Wild.pm
        # Wild.pm - emulate shell @ARGV expansion on shells that don't
        use File::DosGlob;
        @ARGV = map {
                      my @g = File::DosGlob::glob($_) if /[*?]/;
                      @g ? @g : $_;
                    } @ARGV;
        1;
        ^Z
        C:\> set PERL5OPT=-MWild
        C:\> perl -le "for (@ARGV) { print }" */*/perl*.c
        p4view/perl/perl.c
        p4view/perl/perlio.c
        p4view/perl/perly.c
        perl5.005/win32/perlglob.c
        perl5.005/win32/perllib.c
        perl5.005/win32/perlglob.c
        perl5.005/win32/perllib.c
        perl5.005/win32/perlglob.c
        perl5.005/win32/perllib.c

Note there are two distinct steps there: 1) You'll have to create Wild.pm and put it in your perl lib directory. 2) You'll need to set the PERL5OPT environment variable. If you want argv expansion to be the default, just set PERL5OPT in your default startup environment.

If you are using the Visual C compiler, you can get the C runtime's command line wildcard expansion built into perl binary. The resulting binary will always expand unquoted command lines, which may not be what you want if you use a shell that does that for you. The expansion done is also somewhat less powerful than the approach suggested above.


AUTHORS

Gary Ng <71564.1743@CompuServe.COM>
Gurusamy Sarathy <gsar@activestate.com>
Nick Ing-Simmons <nick@ni-s.u-net.com>


 perlwin32 - Perl under Win32