Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How can I obtain a reference to "eval" that works. I'm on perl 5.005-03.

Replies are listed 'Best First'.
(tye)Re: Referece to eval
by tye (Sage) on Jun 06, 2001 at 00:04 UTC
    $code= sub { eval shift }; $code->( 'print "Hi.\n"' );

    Explanations as to why I can't get a direct reference to many of Perl's built-ins are welcome. (: ...Nevermind. It makes sense to me now.

            - tye (but my friends call me "Tye")
(jeffa) Re: Referece to eval
by jeffa (Bishop) on Jun 06, 2001 at 00:03 UTC
    You can only have references to the following:
    • scalars
    • arrays
    • hashes
    • globs
    • _your_ subroutines (not Perl's)
    • packages (objects)
    • compilied regexes
    • and references
    If you need to hang on to a reference to an 'eval', try placing the eval inside a subroutine and reference the subroutine instead. What is the context, by the way?

    UPDATES:
    tye clarified me on 'built-in'
    i added compiled regexes to the list

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
      I have textual representation of functions, one of them is eval. I want to call the function (whatever it is at that moment) with a string arg. On eval it breaks.