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 (Bishop) 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