Skip Menu |
 

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 35772
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: jv [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.19
Fixed in: (no value)



Subject: looks_like_number and overloaded objects
Download (untitled) / with headers
text/plain 428b
looks_like number will return false on objects that stringify or numerify to numbers. use Scalar::Util qw(looks_like_number); my $foo = Foo->new; print "The number is: ", 0+$foo, "\n"; print "The string is: ", "$foo", "\n"; print "Looks like a number: ", looks_like_number($foo) ? "yes" : "no", "\n"; package Foo; sub new { return bless {} }; use overload "+0" => sub { 123 }, '""' => sub { "123" }, fallback => 1;
Subject: Re: [rt.cpan.org #35772] looks_like_number and overloaded objects
Date: Tue, 1 Jul 2008 19:13:51 -0500
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
Download (untitled) / with headers
text/plain 614b
On May 11, 2008, at 8:59 AM, Johan Vromans via RT wrote: Show quoted text
> looks_like number will return false on objects that stringify or > numerify to numbers.
This is intentional. looks_like_number is an API to the looks_like_number implemented internally in perl which does not check for any magic on the SV You can see the test suite already has a test that checks this by using BigInt use Math::BigInt; my $bi = Math::BigInt->new('1234567890'); is(!!looks_like_number($bi), '', 'Math::BigInt'); is(!!looks_like_number("$bi"), 1, 'Stringified Math::BigInt'); Graham.
Subject: Re: [rt.cpan.org #35772] looks_like_number and overloaded objects
Date: Wed, 2 Jul 2008 12:00:19 +0200
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: jv [...] cpan.org (Johan Vromans)
Download (untitled) / with headers
text/plain 575b
[Quoting Graham Barr via RT, on July 1 2008, 20:17, in "Re: [rt.cpan.org #35"] Show quoted text
> This is intentional.
Probably. But it is very confusing. The 'human' interpretation of 'looks like a number' goes for the perceived contents. Perhaps the documentation could be inproved? Returns true EXPR is internally flagged as a number. This does not necessarily corresponds to whether the contents of EXPR looks like a number. In particular, an object will always test false, even if it stringifies or numerifies to a number. See "looks_like_number" in perlapi. -- Johan
Subject: Re: [rt.cpan.org #35772] looks_like_number and overloaded objects
Date: Thu, 3 Jul 2008 08:48:37 -0500
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
Download (untitled) / with headers
text/plain 991b
On Jul 2, 2008, at 5:00 AM, Johan Vromans via RT wrote: Show quoted text
> Queue: Scalar-List-Utils > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=35772 > > > [Quoting Graham Barr via RT, on July 1 2008, 20:17, in "Re: > [rt.cpan.org #35"]
>> This is intentional.
> > Probably. But it is very confusing. The 'human' interpretation of > 'looks like a number' goes for the perceived contents. > > Perhaps the documentation could be inproved? > > Returns true EXPR is internally flagged as a number. > This does not necessarily corresponds to whether the contents of > EXPR looks like a number. In particular, an object will always test > false, even if it stringifies or numerifies to a number. > See "looks_like_number" in perlapi.
I agree the documentation could be clarified, but I am now thinking it should be changed to work because it currently does not work on tied variables either, but the perl implementation does because it cannot tell the difference. Graham.
looks_like_number in Scalar-List-Utils-1.20 now works with tied and overloaded variables


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.