File::DosGlob(3) Perl Programmers Reference Guide File::DosGlob(3) NAME File::DosGlob - DOS like globbing and then some SYNOPSIS require 5.004; # override CORE::glob in(1,8) current package use File::DosGlob 'glob(1,3,7,n)'; # override CORE::glob in(1,8) ALL packages (use with extreme caution!) use File::DosGlob 'GLOBAL_glob'; @perlfiles = glob(1,3,7,n) "..\\pe?l/*.p?"; print <..\\pe?l/*.p?>; # from the command line (overrides only in(1,8) main::) > perl -MFile::DosGlob=glob(1,3,7,n) -e "print <../pe*/*p?>" DESCRIPTION A module that implements DOS-like globbing with a few enhancements. It is largely compatible with perlglob.exe (the M$ setargv.obj version(1,3,5)) in(1,8) all but one respect--it understands wildcards in(1,8) directory components. For example, "<..\\l*b\\file(1,n)/*glob.p?"> will work as expected (in(1,8) that it will find something like '..\lib\File/DosGlob.pm' alright). Note that all path components are case-insensitive, and that backslashes and forward slashes are both accepted, and preserved. You may have to dou- ble the backslashes if(3,n) you are putting them in(1,8) literally, due to dou- ble-quotish parsing of the pattern by perl. Spaces in(1,8) the argument delimit distinct patterns, so "glob(1,3,7,n)('*.exe *.dll')" globs all filenames that end in(1,8) ".exe" or ".dll". If you want to put in(1,8) literal spaces in(1,8) the glob(1,3,7,n) pattern, you can escape them with either double quotes, or backslashes. e.g. "glob(1,3,7,n)('c:/"Program Files"/*/*.dll')", or "glob(1,3,7,n)('c:/Program\ Files/*/*.dll')". The argu- ment is tokenized using "Text::ParseWords::parse_line()", so see Text::ParseWords for details of the quoting rules used. Extending it to csh patterns is left as an exercise to the reader. NOTES Mac OS (Classic) users(1,5) should note a few differences. The specifi- cation of pathnames in(1,8) glob(1,3,7,n) patterns adheres to the usual Mac OS conventions: The path separator is a colon ':', not a slash '/' or backslash '\'. A full path always begins with a volume name. A rel- ative pathname on Mac OS must always begin with a ':', except when specifying a file(1,n) or directory name in(1,8) the current working direc- tory, where the leading colon is optional. If specifying a volume name only, a trailing ':' is required. Due to these rules, a glob(1,3,7,n) like <*:> will find all mounted volumes, while a glob(1,3,7,n) like <*> or <:*> will find all files and directories in(1,8) the current directory. Note that updirs in(1,8) the glob(1,3,7,n) pattern are resolved before the match- ing begins, i.e. a pattern like "*HD:t?p::a*" will be matched as "*HD:a*". Note also, that a single trailing ':' in(1,8) the pattern is ignored (unless it's a volume name pattern like "*HD:"), i.e. a glob(1,3,7,n) like <:*:> will find both directories and files (and not, as one might expect, only directories). The metachars '*', '?' and the escape char '\' are valid characters in(1,8) volume, directory and file(1,n) names on Mac OS. Hence, if(3,n) you want to match a '*', '?' or '\' literally, you have to escape these characters. Due to perl's quoting rules, things may get a bit com- plicated, when you want to match a string(3,n) like '\*' literally, or when you want to match '\' literally, but treat the immediately following character '*' as metachar. So, here's a rule of thumb (applies to both single- and double-quoted strings): escape each '*' or '?' or '\' with a backslash, if(3,n) you want to treat them lit- erally, and then double each backslash and your are done. E.g. - Match '\*' literally escape both '\' and '*' : '\\\*' double the backslashes : '\\\\\\*' (Internally, the glob(1,3,7,n) routine sees a '\\\*', which means that both '\' and '*' are escaped.) - Match '\' literally, treat '*' as metachar escape '\' but not '*' : '\\*' double the backslashes : '\\\\*' (Internally, the glob(1,3,7,n) routine sees a '\\*', which means that '\' is escaped and '*' is not.) Note that you also have to quote literal spaces in(1,8) the glob(1,3,7,n) pat- tern, as described above. EXPORTS (by request only) glob(1,3,7,n)() BUGS Should probably be built into the core, and needs to stop pandering to DOS habits. Needs a dose of optimizium too. AUTHOR Gurusamy Sarathy <gsar@activestate.com> HISTORY Support for globally overriding glob(1,3,7,n)() (GSAR 3-JUN-98) Scalar context, independent iterator context fixes (GSAR 15-SEP-97) A few dir-vs-file optimizations result in(1,8) glob(1,3,7,n) importation being 10 times faster than using perlglob.exe, and using perlglob.bat is only twice as slow as perlglob.exe (GSAR 28-MAY-97) Several cleanups prompted by lack of compatible perlglob.exe under Borland (GSAR 27-MAY-97) Initial version(1,3,5) (GSAR 20-FEB-97) SEE ALSO perl perlglob.bat Text::ParseWords perl v5.8.5 2001-09-21 File::DosGlob(3)