Wow, this is a very interesting trick. I like it a lot. But it's too bad it doesn't help DProf give useful information for anonymous subs:
use Carp;
my $i = 0;
sub foo {
sub {
local *__ANON__ = "local_subref_" . $i++;
carp "blokhead";
};
}
foo()->() for 1 .. 3;
__OUTPUT__
$ perl -d:DProf test.pl
blokhead at test.pl line 7
main::local_subref_0() called at test.pl line 12
blokhead at test.pl line 7
main::local_subref_1() called at test.pl line 12
blokhead at test.pl line 7
main::local_subref_2() called at test.pl line 12
blokhead at test.pl line 7
main::local_subref_3() called at test.pl line 12
$ dprofpp tmon.out
Total Elapsed Time = 0.079705 Seconds
User+System Time = 0.049705 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
...
0.00 - 0.020 3 - 0.0066 main::__ANON__
...
Boo!! DProf still plops everything into main::__ANON__. I've run into this problem before trying to profile code that uses liberal amounts of anonymous subs, and it's quite annoying. Unfortunately I don't know enough about the internals of Perl and DProf to figure out a "clever" solution like yours that works for profiling code (other than using other *Prof modules)...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|