$ 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.