[Chicago-talk] shell expansion

Eric Bohlman ebohlman at earthlink.net
Wed Nov 5 18:10:58 CST 2003


On Wed, 5 Nov 2003 15:35:35 -0800 (PST), Emil Janev <ejanev2 at yahoo.com> 
wrote:

> Here is a question about small problem ( I think ) with shell expansion
> under Windows.
>
> Under UNIX the following would work naturally:
>
> perl -l -e 'print for @ARGV' *
>
> Everything that could be expanded with "echo *" from the current
> directory will be printed.
>
> Under Windows:
>
> C:\Temp>perl -l -e "print for @ARGV" *
>
> It will print just "*". ( echo * yields the same too ).
>
> I used some technique to have the desired under Windows: Imediatelly at
> the begining of the program:
>
> @ARGV = <@ARGV>;
>
> This basically works, but the same script want be portable to UNIX.

What I do is set PERL5OPT to "-MWild" in my Windows environment, and 
include the following module in \perl\lib:

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

That way the program itself doesn't need to know whether it's running 
under a globbing (Unix) or non-globbing (Windows) shell.  I picked this up 
 from somewhere years ago, but I don't remember where.

      



More information about the Chicago-talk mailing list