[ale] OT: interpolation and anchors in perl regex

Ed Cashin ecashin at noserose.net
Sat Oct 18 22:06:40 EDT 2008


On Sat, Oct 18, 2008 at 6:52 PM, Brian Pitts <brian at polibyte.com> wrote:
> Can someone explain why the last one doesn't match?
...
> $ perl -e '$foo = "hello"; $bar = "hello_world"; print "yes\n" if $bar
> =~ /^$foo_world$/;'

There's no $foo_world variable.  If you do "perl -W -e ...",
perl will tell you that.

Using curlies around "foo" makes the match happen.

  bash$ perl -e '$foo = "hello"; $bar = "hello_world"; print "yes\n"
if $bar =~ /^${foo}_world$/;'
  yes


-- 
  Ed Cashin <ecashin at noserose.net>


More information about the Ale mailing list