in reply to Removing glob

Keep in mind that glob($dir . '\\files\\*.txt'); will fail if $dir includes characters special to glob, such as space.

You'd be better off using bsd_glob from File::Glob directly instead of using it via glob. Then, spaces won't be a problem. Other special characters won't cause any harm since they're not found in file names.

There's also the issue that glob acts very specially in scalar context. If you want the first file returned by glob, use ($file)= instead of $file=. If you don't, subsequent calls to glob will return "odd" results.

Replies are listed 'Best First'.
Re^2: Removing glob
by Anonymous Monk on Feb 19, 2011 at 08:18 UTC
    Simply using real slashes, ie glob "$dir/files/*.txt" tends to work regardless of spaces

      No:

      c:\windows\system32>perl -wle "print for glob shift" "C:/Program Files +/*" C:/Program

      Using File::Glob::bsd_glob works as it should:

      c:\windows\system32>perl -MFile::Glob=bsd_glob -wle "print for bsd_glo +b shift" "C:/Program Files/*" C:/Program Files/HP

      ... but the direction of slashes does not matter:

      c:\windows\system32>perl -MFile::Glob=bsd_glob -wle "print for bsd_glo +b shift" "C:\Program Files\*" C:\Program Files\HP