in reply to Re: Finding the name of the target of a coderef
in thread Finding the name of the target of a coderef

The main reason I want to do this is because I'm working on a small script that executes a certain subroutine with certain arguments after x amount of time, a timed event so to say. In order to facilitate ease of use I was hoping to find a way to provide a list of all timed events currently in the queue, with the subroutines they're pointing to, the arguments and the amount of time left till execution.

Remember rule one...
  • Comment on Re^2: Finding the name of the target of a coderef

Replies are listed 'Best First'.
Re^3: Finding the name of the target of a coderef
by revdiablo (Prior) on Apr 15, 2005 at 00:00 UTC

    I would solve that by passing a label along with the coderef when I added the timed event to the queue. Something along the lines of:

    add_to_queue(foo => \&foo, [ @fooargs ], $footime); add_to_queue(bar => \&bar, [ @barargs ], $bartime); dump_queue(); { my @queue; sub add_to_queue { my ($label, $code, $args, $time) = @_; push @queue, [ $label, $code, $args, $time ]; } sub dump_queue { for (@queue) { my ($label, $code, $args, $time) = @$_; print "Will execute $label with @$args at $time\n"; } } }

    Of course, your exact calling conventions will likely be different, but this is just to give you the general idea.