[ale] OT: interpolation and anchors in perl regex

Randy rramsdell at livedatagroup.com
Wed Oct 22 12:03:08 EDT 2008


Brian Pitts wrote:
> 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
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
>   
perl -W -e  '$foo = "hello"; $bar = "hello_world"; print "yes\n" if $bar
=~ /$foo_world$/;'

Name "main::foo_world" used only once: possible typo at -e line 2.
Name "main::foo" used only once: possible typo at -e line 1.
Use of uninitialized value in concatenation (.) or string at -e line 1.
yes


More information about the Ale mailing list