LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

whats the simplest way to find source file and line number of a function (start and end)?

the only way I can think of is parsing the output of

B::Deparse->new("-l")->coderef2text( \&func );

that is something like

{ #line 1852 "/usr/share/perl/5.10/perl5db.pl" ... #line 3541 "/usr/share/perl/5.10/perl5db.pl" (); }

Any easier way?

Cheers Rolf

Replies are listed 'Best First'.
Re: finding source position of function
by chromatic (Archbishop) on Aug 13, 2012 at 22:43 UTC

    Sub::Information can give you the start line. Adding the end line is relatively easy (it's a one-liner).

    With that said, it's easy enough to lie to Perl about line numbers.

      Thanks for the valuable information!

      Actually I was hoping to find a Core-approach w/o such dependencies.

      Luckily I'm only trying to extend the debugger features, where I can do it out of the box.

      It turned out %DB::sub holds the neccessary informations... :)

      Cheers Rolf