Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^5: Stupid question about strings...by AnomalousMonk (Archbishop) |
on Jul 14, 2014 at 23:48 UTC ( [id://1093633]=note: print w/replies, xml ) | Need Help?? |
So why did the code I showed return true (or "foo")?" Because the string defining the regex used in the $str2 =~ $str1 expression (i.e., $str1) has the empty pattern as two (!) of its alternatives, and the empty pattern matches everything. my $str1 = qq(|L|D|); has the empty pattern twice. It doesn't really matter what else is present. The stringization of the output of the qr(\|L\|) expression is a bit complex, but it could be anything.
Update: Changed my $str2 = qq(xyzzy); in third code example above to qq(aaaaa) to eliminate any question of case-insensitive matching.
In Section
Seekers of Perl Wisdom
|
|