in reply to Am I on the pipe, or what?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex without 'm' or '/'
by danger (Priest) on Jul 10, 2002 at 04:05 UTC | |
by hv (Prior) on Feb 24, 2003 at 01:19 UTC | |
|
Thanks, all
by BorgCopyeditor (Friar) on Jul 10, 2002 at 02:03 UTC |