1File::DosGlob(3pm) Perl Programmers Reference Guide File::DosGlob(3pm)
2
3
4
6 File::DosGlob - DOS like globbing and then some
7
9 require 5.004;
10
11 # override CORE::glob in current package
12 use File::DosGlob 'glob';
13
14 # override CORE::glob in ALL packages (use with extreme caution!)
15 use File::DosGlob 'GLOBAL_glob';
16
17 @perlfiles = glob "..\\pe?l/*.p?";
18 print <..\\pe?l/*.p?>;
19
20 # from the command line (overrides only in main::)
21 > perl -MFile::DosGlob=glob -e "print <../pe*/*p?>"
22
24 A module that implements DOS-like globbing with a few enhancements. It
25 is largely compatible with perlglob.exe (the M$ setargv.obj version) in
26 all but one respect--it understands wildcards in directory components.
27
28 For example, "<..\\l*b\\file/*glob.p?"> will work as expected (in that
29 it will find something like '..\lib\File/DosGlob.pm' alright). Note
30 that all path components are case-insensitive, and that backslashes and
31 forward slashes are both accepted, and preserved. You may have to dou‐
32 ble the backslashes if you are putting them in literally, due to dou‐
33 ble-quotish parsing of the pattern by perl.
34
35 Spaces in the argument delimit distinct patterns, so "glob('*.exe
36 *.dll')" globs all filenames that end in ".exe" or ".dll". If you want
37 to put in literal spaces in the glob pattern, you can escape them with
38 either double quotes, or backslashes. e.g. "glob('c:/"Program
39 Files"/*/*.dll')", or "glob('c:/Program\ Files/*/*.dll')". The argu‐
40 ment is tokenized using "Text::ParseWords::parse_line()", so see
41 Text::ParseWords for details of the quoting rules used.
42
43 Extending it to csh patterns is left as an exercise to the reader.
44
46 · Mac OS (Classic) users should note a few differences. The specifi‐
47 cation of pathnames in glob patterns adheres to the usual Mac OS
48 conventions: The path separator is a colon ':', not a slash '/' or
49 backslash '\'. A full path always begins with a volume name. A rel‐
50 ative pathname on Mac OS must always begin with a ':', except when
51 specifying a file or directory name in the current working direc‐
52 tory, where the leading colon is optional. If specifying a volume
53 name only, a trailing ':' is required. Due to these rules, a glob
54 like <*:> will find all mounted volumes, while a glob like <*> or
55 <:*> will find all files and directories in the current directory.
56
57 Note that updirs in the glob pattern are resolved before the match‐
58 ing begins, i.e. a pattern like "*HD:t?p::a*" will be matched as
59 "*HD:a*". Note also, that a single trailing ':' in the pattern is
60 ignored (unless it's a volume name pattern like "*HD:"), i.e. a
61 glob like <:*:> will find both directories and files (and not, as
62 one might expect, only directories).
63
64 The metachars '*', '?' and the escape char '\' are valid characters
65 in volume, directory and file names on Mac OS. Hence, if you want
66 to match a '*', '?' or '\' literally, you have to escape these
67 characters. Due to perl's quoting rules, things may get a bit com‐
68 plicated, when you want to match a string like '\*' literally, or
69 when you want to match '\' literally, but treat the immediately
70 following character '*' as metachar. So, here's a rule of thumb
71 (applies to both single- and double-quoted strings): escape each
72 '*' or '?' or '\' with a backslash, if you want to treat them lit‐
73 erally, and then double each backslash and your are done. E.g.
74
75 - Match '\*' literally
76
77 escape both '\' and '*' : '\\\*'
78 double the backslashes : '\\\\\\*'
79
80 (Internally, the glob routine sees a '\\\*', which means that both
81 '\' and '*' are escaped.)
82
83 - Match '\' literally, treat '*' as metachar
84
85 escape '\' but not '*' : '\\*'
86 double the backslashes : '\\\\*'
87
88 (Internally, the glob routine sees a '\\*', which means that '\' is
89 escaped and '*' is not.)
90
91 Note that you also have to quote literal spaces in the glob pat‐
92 tern, as described above.
93
95 glob()
96
98 Should probably be built into the core, and needs to stop pandering to
99 DOS habits. Needs a dose of optimizium too.
100
102 Gurusamy Sarathy <gsar@activestate.com>
103
105 · Support for globally overriding glob() (GSAR 3-JUN-98)
106
107 · Scalar context, independent iterator context fixes (GSAR 15-SEP-97)
108
109 · A few dir-vs-file optimizations result in glob importation being 10
110 times faster than using perlglob.exe, and using perlglob.bat is
111 only twice as slow as perlglob.exe (GSAR 28-MAY-97)
112
113 · Several cleanups prompted by lack of compatible perlglob.exe under
114 Borland (GSAR 27-MAY-97)
115
116 · Initial version (GSAR 20-FEB-97)
117
119 perl
120
121 perlglob.bat
122
123 Text::ParseWords
124
125
126
127perl v5.8.8 2001-09-21 File::DosGlob(3pm)