Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: 'extract' subs from source code

by 2teez (Priest)
on Oct 24, 2012 at 13:28 UTC ( #1000636=note: print w/ replies, xml ) Need Help??

in reply to 'extract' subs from source code

try this:

use warnings; use strict; while(<ARGV>){ chomp; print $1,$/ if/^sub\s+?(.+?){/; ## print subroutine name if(/^sub\s+?/.. /^}/){ print $_,$/; } }
it works for me.
The code above, is based on the assumption that:
  1. the OP's script(s) start every sub on a new line,
  2. the OP's script(s) and question does not cover anonymous subroutine
However, if these are not so, then all that is needed is to modify the REs used like so:
... chomp; print $1, $/ if /^(?:.+)?\bsub\s+?(.+?){/; ## assumption still her +e if ( /^(.+)?\bsub\s+?(.+?)?{/s .. /^(.+)?}/s ) { ## anonymous sub + included print $_, $/; } ...
Please, it should also be noted that the above may not take care of all subroutrine declaration in perl script.
rovf thanks for the eagle eye ::)

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Comment on Re: 'extract' subs from source code
Select or Download Code
Re^2: 'extract' subs from source code
by rovf (Priest) on Oct 24, 2012 at 13:56 UTC
    Hmmmm.... your solution would at best find those where the word sub occurs at the beginning of the line.

    Ronald Fischer <>

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-07-26 03:14 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (175 votes), past polls