[ale] OT: interpolation and anchors in perl regex

Brian Pitts brian at polibyte.com
Sat Oct 18 18:52:32 EDT 2008


Can someone explain why the last one doesn't match?

$ perl -e '$bar = "hello_world"; print "yes\n" if $bar =~ /^hello_world$/;'
yes

$ perl -e '$foo = "hello"; $bar = "hello"; print "yes\n" if $bar =~
/^$foo$/;'
yes

$ perl -e '$foo = "hello"; $bar = "hello_world"; print "yes\n" if $bar
=~ /$foo_world/;'
yes

brian at triangle:~$ perl -e '$foo = "hello"; $bar = "hello_world"; print
"yes\n" if $bar =~ /^$foo_world/;'
yes

$ perl -e '$foo = "hello"; $bar = "hello_world"; print "yes\n" if $bar
=~ /$foo_world$/;'
yes

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

Thanks,
Brian



More information about the Ale mailing list