The example that BorgCopyeditor supplies with his question brings up an interesting point. Why does this work:      if($query=~$term) {...} Or, to offer a very plain example, why does this work:
if ( 'abc' =~ 'bc' ) { print "yes\n"; }
The rule I learned was (quoting from perlop): "If "/" is the delimiter then the initial m is optional."

Fair enough. The implication is:

if ( 'abc' =~ m/bc/ ) { # good if ( 'abc' =~ /bc/ ) { # good if ( 'abc' =~ m%bc% ) { # good (for any non-alphanum) but: if ( 'abc' =~ 'bc' ) { # BAD! (or so we assume)
But it is not so. As I said above, both of the examples at the top of this response work. Why?

What I cannot find in the on-line docs (update: see danger's response below) but I know from experimentation and the words of Camel 3, page 144, is that, even without the 'm' or the '/', the righthand side of =~ "still counts as a m// matching operation, but there'll be no place to put any trailing modifiers, and you'll have to handle your own quoting."

So...

if ( 'abc' =~ 'bc' ) { # works if ( 'abc' =~ $pattern ) { # works if ( 'abc' =~ "$pattern" ) { # works if ( 'abc' =~ bc ) { # works!! if ( 'abc' =~ 'bc'g ) { # Error: bareword 'g'
The present writer is not responsible for any sideways looks any of these may earn you from your peers.

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall


In reply to Regex without 'm' or '/' by dvergin
in thread Am I on the pipe, or what? by BorgCopyeditor

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.