There's a difference between regexps and strings. To you, "^\w+[\/\w]*$" and /^\w+[\/\w]*$/ may look the same, but to Perl, at least in source code, they're not the same.

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.


In reply to Re: XML & Schema VS Config::IniFiles by bart
in thread XML & Schema VS Config::IniFiles by HeatSeekerCannibal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.