To reflect on ikegami's reply, the reasoning is even simpler: quotemeta is intended to quote the regular expression metacharacters, not the metacharacters of all special syntax string parsing problems. Quotemeta is for perl regex only.
The wildcards in glob() are system-specific; SQL parameter value quoting characters are different from that, and the metacharacters in perl formats, POD and string interpolation are also mini-languages unto themselves. Even for other regex engines, this decision does not hold. How to "escape" these characters also differs between each standard. You escape regex with backslash, sql with arcane quotemarks (or placeholders), format/POD with blank lines or comment marks or tricks with curly braces.
It just so happens that for perl 5 regex, anything that's not a letter or digit might be considered a metacharacter, and could need escaping. The quotemeta() function for perl 5 thus escapes non-letter, non-digit characters, whether they are actually regex special or not. In deciding regex syntax, it was deemed simpler to remember what should be escaped this way. That's likely not what is required for SQL, POD or other usage patterns.
-- [ e d @ h a l l e y . c c ]
| [reply] [d/l] [select] |
quotemeta is intended to quote the regular expression metacharacters, not the metacharacters of all special syntax string parsing problems. Quotemeta is for perl regex only.
I believe "its" intent is to perform as documented. quotemeta is documented to escape all characters except /[A-Za-z_0-9]/. Regular expressions have nothing to do with it. quotemeta can be used anywhere such an escaping scheme is acceptable, including to quote text to include in generated
- regular expressions (/\Q$text\E/),
- sh commands (system("tool \Q$arg\E 2>&1")),
- non-Windows glob patterns (glob("\Q$path\E/*")),
- Perl code (qq{"\Q$text\E/"}),
- etc.
(Note that \Q..\E is just a shortcut for quotemeta.)
The wildcards in glob() are system-specific
Not anymore. They are documented in File::Glob.
Update: Added code samples.
| [reply] [d/l] [select] |