in reply to Overwriting a Constant

Its compile time versus runtime. By the time your A::VALUE is encountered, sub func already substituted 1 for VALUE.

Replies are listed 'Best First'.
Re^2: Overwriting a Constant
by Anonymous Monk on May 05, 2010 at 02:38 UTC
    B::Deparse shows expansion
    $ perl junk Constant subroutine A::VALUE redefined at junk line 12. Constant is 1 $ perl -MO=Deparse junk package A; sub BEGIN { require strict; do { 'strict'->import }; } use constant ('VALUE', 1); sub func { use strict 'refs'; print 'Constant is ', 1, "\n"; } package main; sub BEGIN { use strict 'refs'; require strict; do { 'strict'->import }; } *{'A::VALUE';} = sub () { 2 } ; 'A'->func; junk syntax OK
    See, it shows     print 'Constant is ', 1, "\n"; not     print 'Constant is ', VALUE, "\n";