This code came from the discussion in the thread that includes •Re^5: How to de-reference a coderef?.
BEGIN { package MagicalCoderef; use overload '""' => sub { require B; my $ref = shift; my $gv = B::svref_2object($ref)->GV; sprintf "%s:%d", $gv->FILE, $gv->LINE; }; sub main::Sub (&) { return bless shift, __PACKAGE__; } } my $s = Sub { print +shift }; $s->("hello world\n"); print "$s\n";
In reply to Track the filename/line number of an anonymous coderef by merlyn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |