Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

eval require

by Anarchy (Initiate)
on Nov 07, 2012 at 19:39 UTC ( #1002725=perlquestion: print w/replies, xml ) Need Help??
Anarchy has asked for the wisdom of the Perl Monks concerning the following question:

If you do a eval require with a subroutine, then are you able to use that module used in the require statement when you are no longer inside that subroutine?

Replies are listed 'Best First'.
Re: eval require
by chromatic (Archbishop) on Nov 07, 2012 at 20:37 UTC

    Yes. Module symbols are globally visible.

    With that said, be aware of the difference between using use which takes effect at the point of compilation (such as importing symbols into your namespace) and eval which takes effect as the program runs (and which won't let you refer to those symbols with unqualified names).

    Improve your skills with Modern Perl: the free book.

Re: eval require
by Fletch (Chancellor) on Nov 07, 2012 at 20:01 UTC

    You didn't try it, did you? Please say no. I mean you must not have tried it on your own because the spacetime continuum still exists. Who knows what kind of deviltry could have been unleashed had you experimented and tried to answer a trivial question empirically.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: eval require
by blue_cowdawg (Monsignor) on Nov 07, 2012 at 20:50 UTC
        If you do a eval require with a subroutine,

    Why do you insist on making your life complicated? Just do the darn require....

    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1002725]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2017-12-16 06:44 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (449 votes). Check out past polls.