OT: understanding the ||= operator
--20cf304340987631f3049c0dd858
Content-Type: text/plain; charset=ISO-8859-1
RD> Perl has no proper boolean values. Instead, the boolean operators
RD> treat zero, undef, and the null string '' all as false. Anything else
RD> is true.
to be pedantic, '0' is also false. it isn't exactly the same as 0.
come again with that? how is:
$string = 0; #different from
$string = '0';
they both define $string as something, right?
--20cf304340987631f3049c0dd858--
Re: OT: understanding the ||= operator
>>>>> "sw" == shawn wilson <ag4ve.us [at] gmail.com> writes:
RD> Perl has no proper boolean values. Instead, the boolean operators
RD> treat zero, undef, and the null string '' all as false. Anything else
RD> is true.
sw> to be pedantic, '0' is also false. it isn't exactly the same as 0.
sw> come again with that? how is:
sw> $string = 0; #different from
sw> $string = '0';
sw> they both define $string as something, right?
but they are different actual values. sure perl will convert from one to
the other but i have run into issues with 0 vs '0'. i am comparing
values from input data and from a db using json which stringifys its
values. but it does it differently for 0 and '0' which made the
comparisons fail. the module is checking the internal flags to see if
something is a string or an integer and encoding the json accordingly. i
had to force my string numbers to integers (by adding 0) to make it work
correctly.
and we aren't testing defined, but boolean. defined only checks for
undef.
uri
--
Uri Guttman ------ uri [at] stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/