Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Overwriting a Constant

by biohisham (Priest)
on May 05, 2010 at 18:56 UTC ( [id://838557]=note: print w/replies, xml ) Need Help??


in reply to Overwriting a Constant

In addition to juster's Re: Overwriting a Constant, probably the closest you can get is via simulative (re)setting of constants from the command line by using Getopt::constant, you provide default values - for constants you use (these values can be scalars, lists or even coderefs) - upon 'use'ing Getopt::constant, then from the command line these constants can be made to look like having been assigned new values or used in their original definitions.

Interesting to note is that Getopt::constant does prefix such constants too and this serves to distinguish them by providing a label before the constant name, you can pass empty-string to the ':prefix' label too.

#SYNOPSIS from Getopt::constant document... # Assuming @ARGV is: ('-foo=9,8,7', '-bar', 'wakawaka.txt') use Getopt::constant ( ':prefix' => 'C_', #Can be null too 'foo' => [3,5], 'bar' => 0, ':usage' => "Usage: thingamabob -foo=one,two,three : fooey on these items -bar : enable barriness ", ); # @ARGV is now 'wakawaka.txt', and you've now got # a constant C_foo with value (9,8,7) # and a constant C_bar with value 1

N.B: Nefarious purposes can backfire in a hairy way so 'plot' with caution...


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Log In?
Username:
Password:

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

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

    No recent polls found