pretty sure i've mentioned this before but regex engines (especially in perl) are likely to be highly optimized
You did, and that's what led me to using the regex in the first place :-)
But I run into a minor issue when using /x and the variable has a space, so I don't "love" it. Meaning, let's say that
$foo = 'this and that';. I have to use /this.and.that/ in the regex, which might match "this-and-that" when I don't want it to.
Or, more commonly, I open the script to see if I've mentioned "this and that" anywhere, and have to remember to search for "this and that", "this.and.that", "this.*?that", and "this\W?and\W?that", etc.
Because of those, I'm leaning back towards not using regex; the performance boost isn't worth the extra work on my end.
Now that I'm working with the sun up, though, it's not working like I expected after all!
use feature 'switch';
$foo = 'lorem';
for ($foo) {
when (
'bar' ||
'lorem'
) { print 'yes'; }
default { print 'no'; }
}
I'm expecting 'yes', but get 'no'. If I change it to
$foo = 'bar'; , though, then I get 'yes'.
So maybe it doesn't work quite like I thought, after all? If I have to do this then it totally defeats the purpose:
for ($foo) {
when ('bar') { print 'yes'; }
when ('lorem') { print 'yes'; }
default { print 'no'; }
}
Speed testing using a series of "when" for each condition and no match, it's 4 time slower than "eq".
Making it match the first condition, "when" is 2 times slower than "eq".
Making it match the last condition, it's 3 times slower than using "eq".