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

I don't see the problem with glob and whitespace in filenames. As long as the user understands that glob uses csh rules and escapes whitespace appropriately, it works the same in Windows and in Unix.

Added: Thanks for the examples, now I see what you mean (I've made the same mistakes in the past!).

  • Comment on Re^2: Portability of glob function in a modern perl

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

    A quick search through CPAN (provided by http://cpansearch.bulknews.net/) provides me with following ugly usages of glob that will not work for quoted spaces in the path, as the path is otherwise used for directly constructed filenames too:

    Mac::iPod::GNUPod

    ... my $path = File::Spec->catdir($self->{mnt}, @path); ... # and $self->add_song(glob(File::Spec->catpath($self->{mnt}, "iPod_Control +", "Music", "*", "*")));

    ($self->{mnt} is supposed to be the mount point of the iPod)

    Mail::Action::Role::Purge

    my $dir = $self->storage_dir; ... my @files = map { scalar( s/\.$extension//, basename $_) } glob("$dir/*.$extension");

    ($self->storage_dir is supposed to be the directory for storage, unquoted)

    CDDB::Fake

    ... foreach my $dir ( @ARGV ) { unless ( -d $dir ) { warn("$dir: not a directory -- skipped\n"); next; } ... my @files = sort map { $1 if /([^\/]+)\.mp3$/ } glob("$dir/[0-9]*.mp +3");

    Same as above

    I stopped here, on page three of the results (when searching for glob).In short, a directory and it's glob-safe quoted string are not usable interchangeably, and thus will lead to problems with the authors that can't imagine/foresee whitespace in filenames.

    As an aside, the cpansearch doesn't seem to like searching for "glob(", which would exclude a lot of "typeglob" results.