in reply to Re^3: Portability of glob function in a modern perl
in thread Portability of glob function in a modern perl

I've read the old an new docs and found only the following.

Old perl

perl-5.005_03 perlport
glob EXPR
glob

    Globbing built-in, but only * and ? metacharacters are supported. (Mac OS)

    Features depend on external perlglob.exe or perlglob.bat. May be
 overridden with something like File::DosGlob, which is recommended. (Win32)

    Globbing built-in, but only * and ? metacharacters are supported. Globbing
 relies on operating system calls, which may return filenames in any 
order. As most filesystems are case-insensitive, even ``sorted'' filenames
 will not be in case-sensitive order. (RISC OS) 

perl-5.005_03 perlop
Because globbing invokes a shell, it's often faster to call readdir() yourself
 and do your own grep() on the filenames. Furthermore, due to its current
 implementation of using a shell, the glob() routine may get ``Arg list too long''
 errors (unless you've installed tcsh(1L) as /bin/csh).


perl-5.005_02 perlwin32
File Globbing

    By default, perl spawns an external program to do file globbing. The install
 process installs both a perlglob.exe and a perlglob.bat that perl can use for
 this purpose. Note that with the default installation, perlglob.exe will
 be found by the system before perlglob.bat.

Modern perl

perlport
glob
This operator is implemented via the File::Glob extension on most platforms. 
See File::Glob for portability information.

perlwin32
File Globbing
By default, perl handles file globbing using the File::Glob extension, which 
provides portable globbing.
And both old & new perls say:
Don't count on filename globbing. 
Use opendir, readdir, and closedir instead.
Why can't I count on globbing in a modern perl? I found nothing in the docs.
  • Comment on Re^4: Portability of glob function in a modern perl

Replies are listed 'Best First'.
Re^5: Portability of glob function in a modern perl
by Corion (Patriarch) on Aug 12, 2005 at 09:46 UTC

    The hint Don't count on filename globbing is meant short for Don't count on that all glob parameters on the command line will have been expanded by the calling shell for you, because, on Win32 (and likely VMS), the shell doesn't expand glob filespecs.

    This is unrelated to the glob builtin, which "works" within the boundaries already given. The usage of File::Find and File::Find::Rule is still recommendable over manual reading or globbing via glob, because glob (and File::Glob) live under the assumption that whitespace is a sensible delimiter for glob patterns.

      Don't count on that all glob parameters on the command line will have been expanded by the calling shell for you,
      I seriously doubt that the quoted warning means that. I think the warning means you ought to use opendir/readdir/closedir instead of calling glob.

      Expansion of parameters by the shell (and Unix shells do more expansion that just '*') is the responsibility of the caller - (s)he decides whether or not to call something via the shell or not.

      because, on Win32 (and likely VMS), the shell doesn't expand glob filespecs.
      That became obsolete since the glob emulates chs behavior regardless OS. Isn't it?

        No. Compare the output of the following snippet on Win32 with cmd.exe as the shell and with (say) bash.exe as the (non-default) shell:

        perl -le "print for @ARGV" *

        On Win32 / cmd.exe, this will output:

        Q:\>perl -le "print for @ARGV" * *

        So, obviously, no globbing has taken place.

        Under the bash shell, it outputs a listing of a lot of files, because I started it in a directory with a lot of files:

        bash-2.05b$ perl -le "print for @ARGV" * 44pruefung.py ABGLSAPFIOP.TXT.200405261836 Opics_MurexGD_SapFi.20040526.csv abgleich-MurexGD-SapFi.py abgleich-Opics-MurexGD-SapFi-andere-Konten.py abgleich-Opics-SapFi.py abgleich.py abtest.py go.sh murex_salden_20040526.fi mx_fxdpos_20040526 opics_kassa_20040526.fi opics_termin_20040526.fi ssd_20040526.fi

        This is the difference between the two shells calling Perl, and there is no hidden magic in Perl to unglob stuff.