Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Overwriting a Constant

by Anonymous Monk
on May 05, 2010 at 02:36 UTC ( [id://838434]=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://838434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found