in reply to Case insensitive file testing
Hm. See BUU for a simpler way to do it, but this seemed mildly interesting to me. This WTDI will produce a glob pattern that will match only the wanted files. (I'm currently on windows, so this will only ever give at most one filename, since the OS enforces case-insensitivity. This is, therefore, partaly tested.) Note that this won't work with real paths, only filenames, since the path seperator gets messed with. Makeiglob2 should get around this, but won't case-map things that aren't A-Za-z. A mix between them is possible that will work for both: change the m/^A-Za-z/ in makeiglob2 to m/<os-specifc path metachars>/. (os-specifc path metachars would be \ and : on win32, / on unix-likes, : on macos?) Most of the differences between these two, though, are in though-model. makeiglob is how I think. makeiglob2 is designed to be easy to follow for those newer to perl. Lists are happy things.
sub makeiglob { return join "", map "[\U$_\L$_]", split //, $_[0]; } sub makeiglob2 { $out=""; foreach (split //, $_[0]) { if (m/[^A-Za-z]/) { $out .= $_; } else { $out .= "[" . uc($_) . lc($_) . "]"; } } } print glob(makeiglob(shift));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Possible bug in File::Glob (was Case insensitive file testing)
by blakem (Monsignor) on Sep 18, 2002 at 09:53 UTC |