Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Tuesday, February 19, 2013

Perl glob

Under Win32, if you supply glob() with a string that doesn't contain any wildcards, and there are no files matching your string, you get back one result (your original string). I suppose this makes sense if you are globbing an argument supplied by the user, which might be a single filename or a wildcard spec.

If there are results, they will have a path prefix if there was one in the argument you gave glob. And they won't if there wasn't.

Additionally, the results won't include any subdirectory names that match the wildcard.

Furthermore, with a UNC path you have to represent the leading \\ as \\\\\\\\ - 8 backslashes even in a single quoted string. But you don't have to have more than 1 backslash at any other place in the path.

And beware, you may need to prefix with use File::DosGlob 'glob'; to make glob work natively. NB that even this does not undo the UNC path issue mentioned above - the string that glob is given internally needs 4 consecutive backslashes, and if you construct that string using quotes, the quoted literal needs 8 backslashes.

The documentation says: As a concession to user expectation, therefore, backslashes (under GLOB_QUOTE) only quote the glob metacharacters '[', ']', '{', '}', '-', '~', and backslash itself. All other backslashes are passed through unchanged and this appears to be the same under File::DosGlob.

Further beware that a pattern with a space in won't work in either mode - without the use, glob behaves like split(m/ /,...), and with the use, it returns an empty array.

Followers

Blog Archive