in reply to Re: Proper creation of a negative number
in thread Proper creation of a negative number
... with s///, consider the character class '[\$,]' in favour of the alternation '\$|,'. I expect, but don't know for certain, that the former would quicker ...
I certainly haven't Benchmark-ed it, but I think that with trie optimization for alternations (introduced with 5.10?), a humble alternation like a|b|c gets compiled to [abc] anyway. Even if not, any difference in speed would not, I think, be perceptible unless you were doing a gazillion matches.
... the '\r' modifier which allows you to chain s/// and y/// operations.
I knew about the /r modifier, but I hadn't really thought about chaining these operations in this way! Come to think of it, such chaining was probably a signficant motive for adding this feature. Granted, the left-associativity of =~ !~ looks a bit strange in conjunction with the right-assoc. of assignment (the RHS ends up in the middle of the expression), but I can live with that. Again, I've done no Benchmark-ing, but if forced, I think I'd say this trick was more likely to yield speed increases than attention to character class vs. alternation (at least in simple cases).
Give a man a fish: <%-(-(-(-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Proper creation of a negative number
by kcott (Archbishop) on Jul 09, 2015 at 03:59 UTC |