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

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 xxrc_test_putstep.pl line 206. rcruickshank@heather$ xxrc_test_putstep.pl <***** xxrc_test_step_subs S T A R T S *****> Not a HASH reference at xxrc_test_putstep.pl 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.
Cheers
Ronnie

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2018-09-26 15:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (207 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!