On Apr 27, 2009 at 11:55, Miklos Tirpak <miklos(a)iptel.org> wrote:
Hi,
On 04/24/2009 06:44 PM, Juha Heinanen wrote:
Miklos Tirpak writes:
Both of them would return false. Btw, I do not
think that empty value
is > allowed for to tag, it's a very rare case, and
could be covered with
some explicit check.
to me to tag was just an example of some variable.
We used to write this, but had lots of issues.
The problem happens for
example with @contact.uri.user, when there is no contact header.
Unfortunately the select function can return and error instead of
success with "" value in this case. (The can be also revisited) And 'if
(@contact.uri.user == "")' would evaluate to false because the left had
side value does not exist, which is wrong.
this is exactly my point. you have to first check if something exists
before you start to compare its value to something.
Yes, this could work, but than we need two checks in most of the cases:
if (defined($v) && ($v != "")) {...}
This is more precise indeed, but the script writer should not forget the
extra checks.
We could try some sane defaults (for if ($v)).
For example that's what perl does:
undefined "" string 0 other integer
$foo eq undef true true false false false
$foo == undef true true true true false
$foo eq "" true true false false false
$foo == 0 true true true true false
bool($foo) false false true false true
int($foo) 0 0 0 0 I
str($foo) "" "" S "0"
"I"
Where string == non empty, non-numeric string.
Strings that contain numbers are automatically converted to their
corresponding interger value, e.g. int("3")=3, but
int("a")=int("")=0.
However we are severely impaired by having same comparison and same
addition operators for both strings and intergers.
E.g.: $a == $v is quite messy (what if $a==undef, what to convert $v
to?).
Regarding SER selects, if we go for this solution, I
think we should
revisit all the select functions. For example @foo.param.abcd should
return "" only if the 'abcd' parameter of header 'foo' exists,
but it's
value is empty. Than we could simply check the existence of the parameter:
if (defined((a)foo.param.abcd)) {...}
Note: right now defined @select is always true (and undefined select is
always ""), but I'll change that.
Andrei