[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] OT: interpolation and anchors in perl regex
- Subject: [ale] OT: interpolation and anchors in perl regex
- From: ecashin at noserose.net (Ed Cashin)
- Date: Sat, 18 Oct 2008 22:06:40 -0400
- In-reply-to: <[email protected]>
- References: <[email protected]>
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>