Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: constant and eval (are they enemies?)

by Anonymous Monk
on May 22, 2002 at 19:52 UTC ( #168565=note: print w/replies, xml ) Need Help??

in reply to constant and eval (are they enemies?)

You have to make it return a true value upon success. eval "use constant CONST1 => 5; 1" or warn $@; I'd suggest not using eval though. You can manually do what the use statement does for you.
require constant; constant->import(CONST1 => 5);

Replies are listed 'Best First'.
Re: Re: constant and eval (are they enemies?)
by tune (Curate) on May 22, 2002 at 19:59 UTC
    Thanks. I cannot use the import() thing, because I parse the constant name and the value from a file. That's why I have to use 'eval'...


      Why can't you do
      require constant; constant::->import($name => $value);

        That's happening at runtime, not compile time. While you could put a BEGIN block around it, the code I posted elsewhere in this thread copies the method of the module, without even having to invoke the overhead of the module.

        -- Randal L. Schwartz, Perl hacker

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2022-05-19 02:23 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.