Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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
Replies are listed 'Best First'.
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 chilling in the Monastery: (7)
As of 2015-07-31 10:55 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (276 votes), past polls