in reply to Convenient way to track function calls?

In the same spirit of "useless but I love Perl because it lets me do that kind of thing"!

This will just go through the symbol table, remove functions but store their reference, and call them again, sfter printing a trace, from the AUTOLOAD.

This version only works for the main package but adapting it to work for another one should not be too difficult ;--)

#!/bin/perl -w use strict; # original code sub1(); sub2(); sub1( "foo", "bar"); sub1( "baz"); sub2( "toto", "tata"); sub sub1 { print "this is sub1 running ", join( ', ', @_), "\n"; } sub sub2 { print "this is sub2 running ", join( ', ', @_), "\n"; } # add this to your code my %function; BEGIN {use vars qw( $AUTOLOAD); # grab the function references foreach (keys %::) { # process only functions! if( defined &{$::{$_}}) { next if( $_ eq 'AUTOLOAD'); # leve this one alone $function{"main::$_"}= \&{$::{$_}}; # store the reference undef $::{$_}; # remove the function from the +symbol table } } } sub AUTOLOAD { print "AUTOLOAD running $AUTOLOAD\n"; $function{$AUTOLOAD}->(@_); # call the stored function }