in reply to XML & Schema VS Config::IniFiles
If you want to use a string as a regexp, you should make sure the string is the same as your regexp — for example, when you print it out, what is printed should look like your desired regexp. That means that, at least when using double quotes, you'll have to double our backslashes. And escape that '$'. Or use single quotes, that would solve most of the problems... (except when you want a double backslash, or when it is in front of a single quote. Just double the backslashes, already.)
"^\\w+[\\/\\w]*\$"
But using qr is easier. This is one reason why it was invented: to allow you to create a first class regexp object, that you can store in a variable, with the exact same syntax as you'd use when using the regexp directly.
qr/^\w+[\/\w]*$/
With qr, you don't have to use slashes as the delimiters, you can choose any delimiter (or any pair of delimiters, for paired delimters like "<>", "[]" and "()"), but it'll look even more like a regexp if you do.
BTW to the regexp engine, there's not much difference between a string and a qr object. Most of all, it'll be syntax checked where you put it in the source. Some people (like Abigail-II, not the least of Perl hackers) claim that when deeply nesting qr objects, it'll be much slower than strings.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: XML & Schema VS Config::IniFiles
by HeatSeekerCannibal (Beadle) on Dec 20, 2007 at 19:29 UTC |