tel2 has asked for the wisdom of the Perl Monks concerning the following question:
Beloved Monks,
I'm running Perl 5.16.3 on Linux.
Thanks.
tel2
I seek your wisdom re why the 4th one-liner below returns "Matches!". The other 7 one-liners behave as I would have expected. I thought $a.$b would be the same as "$a$b" in contexts like this - it seems to be with last 'eq' tests. Was I mistaken? If I print them the output looks the same.
I added blank lines above purely for readability.$ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" =~ /A/' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" =~ /C/' $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b =~ /A/' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b =~ /C/' Matches! # WHY??? $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" eq "AB"' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if "$a$b" eq "C"' $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b eq "AB"' Matches! $ perl -e '$a="A";$b="B";print "Matches!\n" if $a.$b eq "C"'
I'm running Perl 5.16.3 on Linux.
Thanks.
tel2
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why is $a.$b not = "$a$b"?
by tybalt89 (Monsignor) on Jul 14, 2020 at 23:30 UTC | |
by tel2 (Pilgrim) on Jul 15, 2020 at 00:08 UTC | |
by LanX (Saint) on Jul 15, 2020 at 00:21 UTC | |
Re: Why is $a.$b not = "$a$b"?
by LanX (Saint) on Jul 15, 2020 at 00:26 UTC | |
by tel2 (Pilgrim) on Jul 15, 2020 at 00:33 UTC | |
Re: Why is $a.$b not = "$a$b"?
by Marshall (Canon) on Jul 15, 2020 at 22:08 UTC |
Back to
Seekers of Perl Wisdom