Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: Referencing a hash of hashes

by Ronnie (Scribe)
on Aug 18, 2006 at 15:07 UTC ( #568178=note: print w/replies, xml ) Need Help??

in reply to Re: Referencing a hash of hashes
in thread Referencing a hash of hashes

Thanks I've implemented your suggestion and am using the tidy -> version. Can I be a pest and ask one further question? (Okay it's really 2 if you count the request!) For audit trail purposes the line -
print "\n\tRunning Step :: $step Sub :: $sub\n" ;

is to be written to a log file for each subroutine run. The $sub value is a reference to a subroutine and I've tried various ways to dereference this into plain text without success - I could be even more tedious and add an entry to the hash that is just text holding the subroutines name. I've been reading pages 251 onwards in Programming Perl and I've had plenty of messages :-
<***** xxrc_test_step_subs S T A R T S *****> Not a SCALAR reference at line 206. rcruickshank@heather$ <***** xxrc_test_step_subs S T A R T S *****> Not a HASH reference at line 206.

but no success! I thought it was something to do with a coderef but I've not yet found an example that works. Sorry to have be a pest.

Replies are listed 'Best First'.
Re^3: Referencing a hash of hashes
by imp (Priest) on Aug 18, 2006 at 15:20 UTC
    You can get this information from B::Deparse.
    sub a { print "foo\n"; } use B::Deparse; my $deparser = B::Deparse->new('-p'); print $deparser->coderef2text(\&a);
    Update - You can get the source of the subroutine with B::Deparse I should have said. Perhaps you meant the name of the subroutine.
      Please note that the code in this post is not the recommended method. It makes uses of B, which is the perl compiler backend. As such it is a little too magical to be used in production code.

      That said, it is interesting to know how to do this, and can be useful at times. This is one way to get the name of a subroutine.

      sub a { print "foo\n"; } use B; # Fetch the internal object for this coderef my $obj = B::svref_2object(\&a); # Fetch the glob for that object my $gv = B::CV::GV($obj); print $gv->NAME;
      My update WAS misleading - it's only the name of the subsoutine that I need.
      Cheers, Ronnie

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2020-10-29 11:47 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (270 votes). Check out past polls.