Are you sure that you want to do this? As you're working at runtime, will you gain anything in defining a constant rather than simply a global, or better, package-scope variable?
Mx. >-----Original Message----- >From: Rodent of Unusual Size [mailto:[EMAIL PROTECTED] >Sent: Tuesday, March 02, 2004 10:42 AM >To: [EMAIL PROTECTED] >Subject: defining 'constants' at run time > > >tell me to piss off for asking here, if you like, but i'm not >on any other perl lists due to traffic. besides, the >responses and advice here have been higher quality. :-) > >i want to be able to define 'constants' in a module at run >time, rather than at compile time. 'use constant' does it too >early. for example: > >use Foo; >my $foo = new Foo; >$foo->mkconst('DOH', 25); >printf("DOH=%d\n", DOH); > >the result i'm looking for is 'DOH=25' on stdout. however, >all i've managed to get is either an error about DOH being a >non-integer, or an unopened filehandle. i've tried things >like having mkconst() do > >my $name = caller() . "::$_[0]"; >eval("\*$name = sub () { $_[1]; }"); > >and that will work -- IFF the caller refers to DOH as &DOH. > >evidently the usage of DOH in the caller has already been >fetched from the symbol table (and found wanting) before the >method has been called. is there any way to defeat that? > >(i hope i'm explaining this lucidly.) >-- >#ken P-)} > >Ken Coar, Sanagendamgagwedweinini http://Ken.Coar.Org/ >Author, developer, opinionist http://Apache-Server.Com/ > >"Millennium hand and shrimp!" > >