On 12-12 19:15, Andrei Pelinescu-Onciul wrote:
On Dec 12, 2008 at 16:41, Jan Janak jan@ryngle.com wrote:
On 11-12 22:01, Andrei Pelinescu-Onciul wrote:
It would be better to have different operators for strings and for integers. Right now we have '+', '==' and '!=' that can be used both for strings and integers. The problem with this approach is that it makes some optimizations impossible, especially when combined with dynamic typed variables (avps or pvars). '+' is especially bad because one can tell what type ($v + x) has only at runtime.
I would like to preserve the original behaviour for strings. They are used much more often than integers. If you need to change anything then, please, consider changing the behaviour of integer operators.
I think having perl like operators would help a lot:
- '.' for string concatenation (instead of reusing '+'), e.g.:
$v= "foo" . "bar"
Yes, I like this one.
- 'eq' instead of == for strings, e.g.: $v eq "bar"
- 'ne' instead of != for strings, e.g.: $v ne "bar"
I don't like this. If there really is a need to have separate operators then use 'eq' and 'ne' for integers and keep == and != for strings. Test (see man test) has string and integer operators this way.
I was using perl as a guideline (since we already have perl like stuff, like ~=).
Yeah, I know, my point was that in SER scripts I've seen we use these operators with strings often and hence we should consider to preserve the behavior for strings (as opposed to integers). I made the remark about test to show that there are differences in existing scripts (perl versus shell).
We could support them right now in parallel with the old ones and obsolete +, == and != for strings in the future (but that means we still cannot optimize '+' in all the cases) or switch right now (maybe with some old compat switch which will support old scripts style). The question is how much are they used right now. While I think '==' and '!=' are used quite often, I'm not sure about '+' for strings (and '+' is the most important anyway).
I guess == and != are used most often with strings.
Note: we can still support '==' and '!=' for condition tests not involving variables (e.g. method=="INVITE", uri=="sip:foo" a.s.o.).
That would be inconsistent. if (method=="INVITE") would work, but if ($abc=="foo") would not work if strings operators are replaced with 'eq' and 'ne'.
Yes, it would be, but I was thinking that most people use it only this way and hence the change would not affect them immediately.
I can neither confirm nor deny this, but at least in ser-oob.cfg operator == is used a lot with strings, so this config, at least, would be affected by such change.
Jan.