Alexander Apprich wrote:

> Andrew,
> 
> andrew Black wrote:
> 
>>In Unix, if you provide a list of wildcards on the command line, by the 
>>time you program sees the list of files.
>>I have program that I call on Unix
>>
>>$    myprog.pl   *.html
>>
>>and the program is basically
>>    while ( <> )
>>    {  do something    }
>>
>>Is there a way of achieving the same on Win32, hopefully in a way that 
>>would still allow my script to run under Unix?
>>
> 
> 
> should be the same depending on what modules/code you are using.
...
> H:\scripts>cmd
> Microsoft Windows 2000 [Version 5.00.2195]
> (C) Copyright 1985-2000 Microsoft Corp.
> 
> The code I used for this...
> 
> use strict;
> use warnings;
> 
> while (<@ARGV>) {
>    print "$_\n";
> }

That's sneaky.  If it's UNIX, the while iterates accross all of the
files listed in @ARGV as expected, but if it's Windoze, it becomes
a glob (*.pl) and expands the glob into the file list.

A more generalized solution would be a BEGIN block with something
like this in it :

BEGIN {

        if ($^O =~ /Win32/i) {
                use File::DosGlob;
                my @argv;
                foreach (@ARGV) {
                        # if wildcard chars and not using globbing shell
                        if (/[*?]/ and $ENV{PERL5SHELL} !~ /sh/) {
                                push @argv, File::DosGlob::glob $_;
                        } else {
                                push @argv, $_;
                        }
                } @ARGV = @argv;
        }
}

>>Related question, what is the difference between Dosglob and perls built 
>>in one

There is a pod in File::DosGlob - read it.  The core glob is a csh
style glob and has been deprecated by File::Glob.  While globbing
is similar in DOS and UNIX, it's not identical esp. in the treatment
of file extensions.

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to