The rule I learned was (quoting from perlop): "If "/" is the delimiter then the initial m is optional."if ( 'abc' =~ 'bc' ) { print "yes\n"; }
Fair enough. The implication is:
But it is not so. As I said above, both of the examples at the top of this response work. Why?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)
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...
The present writer is not responsible for any sideways looks any of these may earn you from your peers.if ( 'abc' =~ 'bc' ) { # works if ( 'abc' =~ $pattern ) { # works if ( 'abc' =~ "$pattern" ) { # works if ( 'abc' =~ bc ) { # works!! if ( 'abc' =~ 'bc'g ) { # Error: bareword 'g'
------------------------------------------------------------
"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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |