wardy3 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to split a string on markers that I don't want to hard-code. My patterns aren't behaving - here's a simple stub of what is throwing me.
use strict; my $patt1 = '!!'; my $patt2 = '++'; my $string = 'hello!!there++everyone!!in the web'; if ( $string =~ m{$patt1} ) { print "Matches patt1\n"; } if ( $string =~ m{\Q $patt2 \E}x ) { print "Matches patt2 with /x\n"; } if ( $string =~ m{\Q$patt2\E} ) { print "Matches patt2\n"; }
I would have thought this would have matched all 3 times but the /x modifier doesn't match it. Does the \Q\E make the spaces significant?
Can someone see why?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: /x modifier with \Q and \E
by NetWallah (Canon) on Apr 01, 2008 at 05:37 UTC | |
by wardy3 (Scribe) on Apr 01, 2008 at 05:47 UTC | |
by parv (Parson) on Apr 01, 2008 at 05:58 UTC | |
|
Re: /x modifier with \Q and \E
by parv (Parson) on Apr 01, 2008 at 05:27 UTC | |
by wardy3 (Scribe) on Apr 01, 2008 at 05:40 UTC | |
by parv (Parson) on Apr 01, 2008 at 05:54 UTC | |
by wardy3 (Scribe) on Apr 01, 2008 at 08:32 UTC |