this line gives me syntax error:
if ($fU == null) {
how should it be written?
-- juha
On May 30, 2009 at 12:16, Juha Heinanen jh@tutpro.com wrote:
this line gives me syntax error:
if ($fU == null) {
how should it be written?
I thing if ($fU == $null)
or better: if (!defined $fU)
Andrei
On Jun 01, 2009 at 17:48, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
I thing if ($fU == $null)
or better: if (!defined $fU)
just for curiosity, is performance of the above two equivalent?
No, there are very minor differences:
!defined $fU fastest $fU == "" - extra string conversion $fU == $null slowest (has to go through a pv call and string or integer conversion)
Andrei
Andrei Pelinescu-Onciul writes:
No, there are very minor differences:
!defined $fU fastest
ok, please change the syntax.
$fU == "" - extra string conversion
this i don't understand. if i assign $something = "", then $something is defined and test defined $something should return true.
$fU == $null slowest (has to go through a pv call and string or integer conversion)
-- juha
On Jun 01, 2009 at 18:59, Juha Heinanen jh@tutpro.com wrote:
Juha Heinanen writes:
!defined $fU fastest
one more question related to this: how do i make a variable "undefined"? is there a function uset($foo) or undefine($foo)
no
or do i need to use slow method
$foo = $null
Yes, assign anything that is undefined, e.g.:
$foo = $undefined_value will work too.
Andrei
On 06/01/2009 07:19 PM, Andrei Pelinescu-Onciul wrote:
On Jun 01, 2009 at 18:59, Juha Heinanen jh@tutpro.com wrote:
Juha Heinanen writes:
!defined $fU fastest
one more question related to this: how do i make a variable "undefined"? is there a function uset($foo) or undefine($foo)
no
just for PV case, there is a function exported by pv module pv_unset("$pv"): http://sip-router.org/docbook/sip-router/branch/master/modules_k/pv/pv.html#...
Cheers, Daniel
or do i need to use slow method
$foo = $null
Yes, assign anything that is undefined, e.g.:
$foo = $undefined_value will work too.
Andrei
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Daniel-Constantin Mierla writes:
just for PV case, there is a function exported by pv module pv_unset("$pv"): http://sip-router.org/docbook/sip-router/branch/master/modules_k/pv/pv.html#...
thanks, that made it.
-- juha
On 06/01/2009 07:32 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
just for PV case, there is a function exported by pv module pv_unset("$pv"): http://sip-router.org/docbook/sip-router/branch/master/modules_k/pv/pv.html#...
thanks, that made it.
welcome, anyhow, what Andrei suggested works as well, e.g., $ab = $null; $ab = $some_undef_pv;
Daniel
On 06/01/2009 07:37 PM, Juha Heinanen wrote:
Daniel-Constantin Mierla writes:
welcome, anyhow, what Andrei suggested works as well, e.g., $ab = $null; $ab = $some_undef_pv;
yes, but i assume that that is again slower because of the pv lookup.
well, the execution speed in this case is not a concern at all. You can check with benchmark the difference.
Cheers, Daniel
On Jun 01, 2009 at 18:56, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
No, there are very minor differences:
!defined $fU fastest
ok, please change the syntax.
If you mean defined ($fU), instead of defined $fU, I prefer defined $fU (is more perl-like) and defined ($fU) or defined($fU) works anyway.
$fU == "" - extra string conversion
this i don't understand. if i assign $something = "", then $something is defined and test defined $something should return true.
== is for comparisons not for assignment. If I compare an undefined value with "" in most languages is true.
$fU == $null slowest (has to go through a pv call and string or integer conversion)
Andrei
Andrei Pelinescu-Onciul writes:
If you mean defined ($fU), instead of defined $fU, I prefer defined $fU (is more perl-like) and defined ($fU) or defined($fU) works anyway.
great, i tested and also defined($fU) works!
this i don't understand. if i assign $something = "", then $something is defined and test defined $something should return true.
== is for comparisons not for assignment. If I compare an undefined value with "" in most languages is true.
empty string "" is a very well defined string value. it has nothing to do with UNDEFINED. i could accept that it would be consider FALSE in a test, but not UNDEFINED.
regarding "most languages", perhaps perl is such, but even in php, "" value is a defined (set) value:
$var = '';
// This will evaluate to TRUE so the text will be printed. if (isset($var)) { echo "This var is set so I will print."; }
how do we solve this problem? cast a vote or what?
-- juha
On Jun 01, 2009 at 19:27, Juha Heinanen jh@tutpro.com wrote:
Andrei Pelinescu-Onciul writes:
If you mean defined ($fU), instead of defined $fU, I prefer defined $fU (is more perl-like) and defined ($fU) or defined($fU) works anyway.
great, i tested and also defined($fU) works!
this i don't understand. if i assign $something = "", then $something is defined and test defined $something should return true.
== is for comparisons not for assignment. If I compare an undefined value with "" in most languages is true.
empty string "" is a very well defined string value. it has nothing to do with UNDEFINED. i could accept that it would be consider FALSE in a test, but not UNDEFINED.
Think of it as automatic conversion.
regarding "most languages", perhaps perl is such, but even in php, "" value is a defined (set) value:
$var = '';
// This will evaluate to TRUE so the text will be printed. if (isset($var)) { echo "This var is set so I will print."; }
This will evaluate to TRUE also in sip-router (if (defined($var))). The question is how is if ($foo == "") evaluated when $foo is undefined in php.
how do we solve this problem? cast a vote or what?
Why would you want sip-router to behave differently then other scripting languages? I agree that comparing with undefined is and undefined operation so any solution is more a matter of convention then logic (from a strictly logical point of view it should throw an error), but since the convention and what most people expect is that comparing and undefined value to "" should return TRUE, why innovate?
Andrei
Andrei Pelinescu-Onciul writes:
$var = '';
// This will evaluate to TRUE so the text will be printed. if (isset($var)) { echo "This var is set so I will print."; }
This will evaluate to TRUE also in sip-router (if (defined($var))). The question is how is if ($foo == "") evaluated when $foo is undefined in php.
fine if defined($var) on $var = "" is true.
Why would you want sip-router to behave differently then other scripting languages?
i don't want that. in php
unset($foo); if ($foo == "") { echo "yes\n"; } else { echo "no\n"; }
prints "yes", but
unset($foo); if ($foo === "") { echo "yes\n"; } else { echo "no\n"; }
prints "no".
=== operator thus allows me to tell, if a var is undefined or assigned "" value.
== is not good for testing if variable is defined, which prompted this discussion:
!defined $fU fastest $fU == "" - extra string conversion $fU == $null slowest (has to go through a pv call and string or integer conversion)
so the middle one is not ok for that purpose, but it doesn't need to be because defined() exists.
-- juha