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

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.
UPDATE:
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 <ynnor@mm.st>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-12-27 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls