3 ms·
> Finally, there's a way to stop non-identical strings from matching just because they have the same numerical value. Um, this has been there for decades:
by raldi 11y ago
> Finally, there's a way to stop non-identical strings from matching just because they have the same numerical value.
Um, this has been there for decades:
$a = '123';
$b = '123.0';
print $a == $b ? 'y' : 'n'; # prints y
print $a eq $b ? 'y' : 'n'; # prints n
- kbenson 11y agoI read it that way at first, and was going to comment on it, then I figured the point was smart match being able to distinguish, not being able to do your own test.
- osswid 11y ago'eq' does the test you are asking for.
- kbenson 11y agoYes, I'm aware, but when using smart matching (that is, the given/when pair which has had it's fair share of trouble, and is currently experimental after having not been), you sometimes want to be able to distinguish between those types of tests when doing a smart match[1]. I believe the article was referencing this, and so while yes, anyone who knows how to use Perl will use the appropriate operator for the appropriate type of type operation, there are reasons to still want to distinguish what type of match is done by the smart match operator, '~~'. 1: http://perldoc.perl.org/perlop.html#Smartmatch-Operator http://perldoc.perl.org/perlop.html#Smartmatch-Operator