Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Loading a Module from a Variable

by nobull (Friar)
on Sep 21, 2005 at 16:46 UTC ( [id://493867]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Loading a Module from a Variable
in thread Loading a Module from a Variable

eval, unlike require does not evaluate the code in a new top-level lexical scope. Any lexically scoped varaibles or pragmas will be inherited by the code.

One way to avoid use strict and use warnings being inherited by your evaled source is to simply no strict; no warnings; before you eval.

To avoid lexical variables, put the eval() in a subroutine that appears before any file scoped lexicals (and before the pragmas too).

# Start of program sub myeval { eval shift } use strict; use warnings; # ...rest of program

A completely different approach would be to put a code reference into @INC. That way you can actually use require.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://493867]
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 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found