Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Constant CPAN distribution.

Report information
The Basics
Id: 67525
Status: resolved
Priority: 0/
Queue: Constant

People
Owner: Nobody in particular
Requestors: pause [...] tlinx.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.20
Fixed in: 1.21



Subject: constant doesn't work with UTF-8 identifier
I was trying to define a constant for 'pi' using it's UTF-8 character, 'π', (U+03C0). It doesn't work as shown by the following program (displays pi 3 ways: using the ascii name 'pi', using 'Readonly' to define the scalar $π, and trying to define it using the actual character for pi (π): #!/usr/bin/perl -w use feature ':5.10'; use utf8; use Readonly; binmode STDOUT, 'encoding(UTF-8)'; use constant pi => 4*atan2(1,1); printf "pi=%7.6f\n", pi; #doesn't work use constant π => 4*atan2(1,1); printf "π=%7.6f\n", π; Readonly my $π => 4*atan2(1,1); printf "π=%7.6f\n", $π;
Subject: Re: [rt.cpan.org #67525] constant doesn't work with UTF-8 identifier
Date: Sun, 17 Apr 2011 12:15:45 +0200
To: bug-Constant [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
Linda A Walsh wrote via RT: Show quoted text
> I was trying to define a constant for 'pi' using it's UTF-8 character, > 'π', (U+03C0). It doesn't work as shown by the following program > (displays pi 3 ways: using the ascii name 'pi', using 'Readonly' to > define the scalar $π, and trying to define it using the actual > character > for pi (π):
Interestingly, it did work in 5.8, but stopped working in 5.10 and following versions. In fact, nothing in constant.pm prevents you from defining a name with Unicode characters. And given that the resulting function is correctly called in 5.8, I would say it's either a regression in 5.10, or it's a intended behaviour. In all cases, I would say the problem lies more in Perl itself than in constant.pm -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
Subject: Re: [rt.cpan.org #67525] constant doesn't work with UTF-8 identifier
Date: Sun, 17 Apr 2011 14:40:08 +0200
To: bug-Constant [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
$ cat pi use utf8; binmode STDOUT, 'encoding(UTF-8)'; use constant π => 4*atan2(1,1); printf "constant π = %.6f\n", π; $ perl5.8.6 pi constant π = 3.141593 $ perl5.10.1 pi Argument "\x{3c0}" isn't numeric in printf at pi line 8. constant π = 0.000000 $ perl5.10.1 -Mstrict pi Bareword "π" not allowed while "strict subs" in use at pi line 8. Execution of pi aborted due to compilation errors. The difference is that in 5.8, a constant is created using a subroutine: no strict "refs"; my $name = "π"; *$name = sub () { 4*atan2(1,1) }; while in the next major versions of Perl, starting with 5.9.2, a constant is an inlined reference: no strict "refs"; my $name = "π"; my $scalar = 4*atan2(1,1); my $pkg = __PACKAGE__; my $symtab = \%{$pkg . "::"}; Internals::SvREADONLY($scalar, 1); $symtab->{$name} = \$scalar; I had forgot that aspect in my previous mail, so disregard what I said ;) Throwing B::Deparse in the process, it looks like "π" isn't recognised as a symbol name: $ perl5.10.1 -MO=Deparse pi use utf8; binmode STDOUT, 'encoding(UTF-8)'; use utf8 (); use constant ('π', 3.141592653589793116); printf "constant \x{3c0} = %.6f\n", 'π'; pi syntax OK while in the case of a constant with a more traditional name, the symbol is optimised away at compile time, and is therefore not even visible to B::Deparse: $ cat pi2 use constant pi => 4*atan2(1,1); printf "constant pi = %.6f\n", pi; $ perl5.10.1 -MO=Deparse pi2use constant ('pi', 3.141592653589793116); printf "constant pi = %.6f\n", 3.141592653589793116; pi2 syntax OK So I'd say this still looks more like a bug in Perl than a bug in constant.pm -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
On Sun Apr 17 08:39:57 2011, SAPER wrote: Show quoted text
> So I'd say this still looks more like a bug in Perl than a bug in > constant.pm >
’Tis a bug in perl, and a deeply-ingrained one, too. Since a real fix would be too intrusive during code freeze, I have modified constant.pm to imitate the (buggy) perl internals when looking up stash entries. See: http://perl5.git.perl.org/perl.git/commitdiff/d12b49d
Subject: Re: [rt.cpan.org #67525] constant doesn't work with UTF-8 identifier
Date: Mon, 18 Apr 2011 10:48:47 +0200
To: bug-Constant [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
Father Chrysostomos wrote via RT: Show quoted text
> On Sun Apr 17 08:39:57 2011, SAPER wrote:
>> So I'd say this still looks more like a bug in Perl than a bug in >> constant.pm
> > ’Tis a bug in perl, and a deeply-ingrained one, too. Since a real fix > would be too intrusive during code freeze, I have modified constant.pm > to imitate the (buggy) perl internals when looking up stash entries.
Yup, I saw your mail on P5P. I'm currently adjusting the code to make it work on older Perls as well. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
Subject: Re: [rt.cpan.org #67525] constant doesn't work with UTF-8 identifier
Date: Mon, 18 Apr 2011 13:51:04 +0200
To: bug-Constant [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
This bug should be fixed with release 1.21, just uploaded on the CPAN, sponsored by the Perl QA Hackathon 2011 in Amsterdam. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
On Mon Apr 18 07:50:59 2011, SAPER wrote: Show quoted text
> This bug should be fixed with release 1.21, just uploaded on the > CPAN, sponsored by the Perl QA Hackathon 2011 in Amsterdam. >
---- (Verified as solving my original problem...) thanks!