dsb has asked for the wisdom of the Perl Monks concerning the following question:
It started when I found out that you could use whitespace after the m, so long as the whitespace was followed by a word character.
Yes its ugly, and probably a bad idea but I thought it might make for a funky piece to an obfu. So I started playing around:$str =~ m TpatternTi;
Okay, line 17 is the last line of the script and everything else is commented out so I'm 99.9% sure its no glitch in my code. And the bracket is definitely there so what gives?# the only obfu'd part of this code would be the regex # which fails anyway so nevermind the obfu # more concerned with the behavior $str = "foobar fOObar"; $x = qr/(foo)/i; print $1 while ($str =~ m _${x}_g); print "\n"; # prints 'foofOO\n' to STDOUT - fine $str = "foobar fOObar"; $x = "(foo)"; print $1 while ($str =~ m _${x}_g); print "\n"; # prints 'foo\n' to STDOUT - also fine # this is where it gets weird # and of course the part I most badly wanted to work $str = "foobar fOObar"; $_ = qr/(foo)/i; print $1 while ($str =~ m _${_}_g); print "\n"; # throws error: # Missing right bracket at az.pl line 17, within pattern
At first I thought that maybe there was no interpolation performed if you used the whitespace+word character delimiter, but it works fine with $x
Any ideas?
BTW, it doesn't look particularly confusing after all, but I'd still like to know what's happening here ;0).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error with Regex Interpolation
by japhy (Canon) on Apr 22, 2002 at 21:04 UTC | |
|
Re: Error with Regex Interpolation
by Chmrr (Vicar) on Apr 22, 2002 at 21:12 UTC |