The reason for the observed behaviour is that a regex with "s as the delimiter get interpolated as a string, before it gets treated as a regex.

I think that the docs are simply out of date or perhaps somewhat badly phrased. Any expression on the right-hand side of =~ or !~ is treated as a regex.

print 'String contains a zero' if '0' =~ 0; String contains a zero $_ =~ join '|', 0, 1 and print "'$_' contains a '0' or a '1'" for qw[ 0 2 50 02 1 11 abc1 def]; '0' contains a '0' or a '1' '50' contains a '0' or a '1' '02' contains a '0' or a '1' '1' contains a '0' or a '1' '11' contains a '0' or a '1' 'abc1' contains a '0' or a '1' $_ !~ join '|', 0, 1 and print "'$_' doesn't contains a '0' or a '1'" for qw[ 0 2 50 02 1 11 abc1 def]; '2' doesn't contains a '0' or a '1' 'def' doesn't contains a '0' or a '1'

The only time the 'm' or '/'s are required is when implicitly comparing against $_.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

In reply to Re: Re: Re: Re: what function of this Regular Expression? by BrowserUk
in thread what function of this Regular Expression? by iwanthome

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.