Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: perl determine a subroutine name by given line

by cdarke (Prior)
on Aug 05, 2011 at 09:15 UTC ( [id://918708]=note: print w/replies, xml ) Need Help??


in reply to perl determine a subroutine name by given line

The closest I can come-up with is B::Xref (in the base):
perl -MO=Xref,d script-name.pl
which gives you the last line-number of each subroutine definition.

Replies are listed 'Best First'.
Re^2: perl determine a subroutine name by given line
by duelafn (Parson) on Aug 05, 2011 at 11:05 UTC

    Not quite. It seems to give the line number where the subroutine becomes known to perl. Thus, if the sub is used before it is defined the line numbers will be wrong. Example:

    #!/usr/bin/perl use 5.010; say f( 34 ); sub f { $_[0] + 8 }

    Then, perl -MO=Xref,d /tmp/test.pl gives (among other things):

    Package main &f s3

    Which is the line where f is used, not defined.

    This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi

    Good Day,
        Dean

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://918708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-23 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found