in reply to Re: filtering file names to be added to an array...maybe.
in thread filtering file names to be added to an array...maybe.

Doesn't glob use the system shell to grab a file list? The OP mentioned that the script needs to run on both NT and *nix. I'm not sure that it would cause any problems in this case, but it could be a potential portability issue.

----
Coyote

  • Comment on Re: Re: filtering file names to be added to an array...maybe.

Replies are listed 'Best First'.
Re: Re: Re: filtering file names to be added to an array...maybe.
by chipmunk (Parson) on Jun 06, 2001 at 19:36 UTC
    Up to perl5.005_03, glob in Perl spawned a shell. However, as of 5.6.0, glob is implemented using the File::Glob extension (offsite link), which doesn't spawn a shell, and provides configuration options besides.
Re: Re: Re: filtering file names to be added to an array...maybe.
by myocom (Deacon) on Jun 06, 2001 at 09:33 UTC

    As the docs say, it globs like /usr/sh would. And I tested this sort of glob on Win32 and it worked just fine.

    Update: Excellent point, Coyote.

      There is a small issue with glob between Win32 and *nix. Consider a directory that contains files named "uc.DAT" and "lc.dat". Let's use this code to glob all files with an extension of dat on a linux box and a Win98 box (I don't have an NT box handy so YMMV).

      #!/usr/bin/perl -w use strict; use Data::Dumper; my @files = glob('*.dat'); print Dumper(\@files);
      Running this on linux yields this output:

      $VAR1 = [ 'lc.dat' ];
      On Windows 98, you get the following:

      $VAR1 = [ 'lc.dat', 'uc.DAT' ];

      The problem here is that Windows is case insensitive, but case preserving. This could be a potential problem if you are expecting the same output from glob on both platforms.

      ----
      Coyote

Re: Re: Re: filtering file names to be added to an array...maybe.
by sierrathedog04 (Hermit) on Jun 06, 2001 at 15:14 UTC
    If the C shell exists then Perl will use it to do filename globbing. The benefit of using the C shell is that it properly handles filenames with spaces in them, whereas some other shells do not.