3 ms·
Don't use it in Perl 5. You have to first read the whole documentation on what when does[1] and then the whole documentation on what smartmatch does[2] and then
by Grinnz 7y ago
Don't use it in Perl 5. You have to first read the whole documentation on what when does[1] and then the whole documentation on what smartmatch does[2] and then you probably still won't know what will happen if you compare two values that might or might not be numbers, because Perl does not make this distinction for you, so smartmatch guesses. There is a reason every other operator has explicit stringy and numeric comparison versions, and optional new stringy bitwise operators were added because they had the same ambiguity[3].
[1] https://perldoc.pl/perlsyn#Experimental-Details-on-given-and-when https://perldoc.pl/perlsyn#Experimental-Details-on-given-and...
[2] https://perldoc.pl/perlop#Smartmatch-Operator https://perldoc.pl/perlop#Smartmatch-Operator
[3] https://perldoc.pl/feature#The-'bitwise'-feature https://perldoc.pl/feature#The-'bitwise'-feature
- Grinnz 7y agoA more explicit switch statement for only strings or numbers is available from CPAN: https://metacpan.org/pod/Switch::Plain https://metacpan.org/pod/Switch::Plain