Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: how can I access code ref contents, not call it?

by autark (Friar)
on Jan 04, 2001 at 05:47 UTC ( #49668=note: print w/replies, xml ) Need Help??


in reply to how can I access code ref contents, not call it?

With perl 5.6 you should be able to say:
use B::Deparse; sub bar { print "foo" } my $deparse = B::Deparse->new(); my $body = $dep->coderef2text(\&bar); print $body;
(See perldoc B::Deparse). This returns the coderef as plain text. Or you might use the B module via the O module to do some of the work yourself.

Autark.

Replies are listed 'Best First'.
Re (tilly) 2: how can I access code ref contents, not call it?
by tilly (Archbishop) on Jan 04, 2001 at 05:55 UTC
    If you try that, it is not reliable. In the case of closures there can be considerable context which you miss. Such as which variables are global and which are private lexicals, and in the latter case what are the values of said lexicals.

    There will be far fewer scoping games to cope with if you compile it yourself in a known scope.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2020-12-01 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (11 votes). Check out past polls.

    Notices?