Forum Moderators: coopster & phranque

Message Too Old, No Replies

Thoughts on smartmatch (~~)

         

csdude55

8:34 pm on Dec 27, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's been over a decade, do you think it's safe to use smartmatch and disable warnings?

I really only use it when I'm dealing with an array; eg, replacing this:

$str = 'foo';

if ($str eq 'foo' ||
$str eq 'bar' ||
$str eq 'lorem') {
# do stuff
}

with this:

$str = 'foo';

if ($str ~~ ['foo', 'bar', 'lorem']) {
# do stuff
}

If you don't think I should use it, can you suggest an alternative? I know there's a smart::match module, but I would consider that a last resort for a relatively minor feature.