Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2018-01-20 21:37 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.