7stud has asked for the wisdom of the Perl Monks concerning the following question:

use strict; use warnings; use 5.010; my @files = glob "/Volumes/nameA nameB/*"; for (@files) { say; }

The volume name is "nameA nameB", i.e two words with a space in the middle. The output on mac os x is:

/Volumes/nameA

What am I doing wrong? It feels like I am in Windows hell.

Replies are listed 'Best First'.
Re: glob operator problems
by 7stud (Deacon) on Jan 15, 2010 at 05:33 UTC

    The glob docs say this:

    Note that "glob" will split its arguments on whitespace, treating each segment as separate pattern.

    Great. How do I get around that? I tried escaping the space:

    my @files = glob "/Volumes/NIKON\ D5000/*.*";
    Ah. I was in windows hell. I need two backslashes so that the literal '\ ' is seen by perl? The shell?
      Or use bsd_glob from File::Glob. The only difference between the two is that bsd_glob doesn't treat spaces specially.

      Ah. I was in windows hell. I need two backslashes so that the literal '\ ' is seen by perl? The shell?

      That's undeserved Microsoft bashing. Not only does the shell not do what you say, it would actually be a good thing if it did!

      No, the problem is with using an unescaped slash in double quotes.

        I would not use "\" even on windows paths it makes the pathnames "ugly" id rather use perl syntax (Perl converts it to the systems needs): e.g.: c:/my/path/ ...

        Thanks
        MH

A reply falls below the community's threshold of quality. You may see it by logging in.