On Fri, Mar 11, 2022 at 6:34 PM Yuki Kimoto <kimoto.yuki@gmail.com> wrote: > > 2022-3-11 10:50 Dan Book <grinnz@gmail.com> wrote: > >> On Thu, Mar 10, 2022 at 8:42 PM Darren Duncan <darren@darrenduncan.net> >> wrote: >> >>> On 2022-03-10 5:19 p.m., Yuki Kimoto wrote: >>> > I have a question. >>> > >>> > What means the scalar value is created as a number for JSON >>> serialization? >>> > >>> > # Created as a number >>> > my $num = 0; >>> > >>> > # Replace 0 with "0" >>> > $num =~ s/0/0/; >>> > # Is this result 0 or "0"? >>> > my $json_num = to_json $num; >>> >>> The result is absolutely certainly a string, because it is the result of >>> a >>> regular expression, which is a string operation. >>> >>> Its logically the same as if you had said: >>> >>> my $num = ''.$num; >>> >>> So "0" is the result in $json_num. >>> >> >> To add: it is about the value being created as a string or a number, not >> a variable. The result of a s///, or any string or numeric operation, is a >> new value. >> >> -Dan >> > > Darren, Dan, Yves > > Thank you for telling me the difference between a variable and a value. > > I have another question. > > If the two "created_as_number" and "is_number" functions existed, what > cases would the two functions return the different results? > > That is difficult to answer because Perl's current type system does not support defining a value as a number for a hypothetical "is_number". This would be a task for the type system discussions to determine. -DanThread Previous | Thread Next