Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Get a function argument's name

by slaniel (Acolyte)
on Jul 05, 2006 at 17:24 UTC ( #559393=perlquestion: print w/replies, xml ) Need Help??

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

I've got a function that takes a function argument, and I'd like to be able to extract the name of the function argument. Something like this must be possible, because caller() can extract function names from the call stack. Now I just want to extract the name of a function argument.

Replies are listed 'Best First'.
Re: Get a function argument's name
by Roy Johnson (Monsignor) on Jul 05, 2006 at 17:53 UTC
      That did the trick! Thanks a bunch.
Re: Get a function argument's name
by graff (Chancellor) on Jul 05, 2006 at 17:34 UTC
    It might help if you post a snippet of (pseudo) code that shows what you are trying to accomplish. If the code you post actually fails to do what you want, it will be easier for us to see what it does, and maybe then we can figure out how to make adjustments so that it will do what you want.
      Sure. I'm writing a little function to run another function on a given set of arguments and time how long it takes. Looks like so:
      sub run_and_time(&@) { use Time::HiRes; my $func = shift; my $funcName = [some bit of code to get $func's name] my $start_time = [gettimeofday]; my @retlist = &{$func}(@_); print "Time to run $funcName: ", tv_interval($start_time), "\n"; }
      So I need some way to get $funcName. Does that clarify things?
        Er, is there something wrong with Benchmark? Specifically: "timethis - run a chunk of code several times". Or maybe "timethese - run several chunks of code several times".

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://559393]
Approved by Roy Johnson
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2021-05-07 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (91 votes). Check out past polls.

    Notices?