note
merlyn
To make that even simpler, you could write a subroutine called <tt>Sub</tt> that takes a coderef argument and records its file and line number and returns an object that when used as a coderef invokes the coderef, but when used as a string returns the filename/linenumber of creation. How's that for slick? I may even have to code that up for a snippet. Usage would be something like:
<code>
my $sub = Sub { my $x = shift; print $x };
$sub->("foo"); # prints foo
print "that was from $sub\n";
</code>
Pretty simple to do.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-9073">
<p>-- [http://www.stonehenge.com/merlyn/|Randal L. Schwartz, Perl hacker]
<br>
Be sure to read [id://205373|my standard disclaimer] if this is a reply.</p>
</div></div>
<hr>
<b>update:</b> see [id://413725].
413556
413628