Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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

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 <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?
[marioroy]: Is List::Util::XS a core Perl module?
[stevieb]: corelist List::Util::XS says "List::Util::XS was first released with perl v5.10.1"
[stevieb]: so yes, since v5.10.1 :)
[MidLifeXis]: According to [metaperl:// corelist], Perl 5.10.1
Lady_Aleena blurbles. One of her favorite modiles is now in "maintenance mode" in favor of a new fangled module.
[MidLifeXis]: D'oh. Slow out of the gate.
[marioroy]: Thanks stevieb, MidLifeXis.
[MidLifeXis]: corelist Typo. Wow. Time to go, fingers are malfunctioning.
[marioroy]: Thanks MidLifeXis. Leaned another thing about Perl. Wow.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2017-05-24 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?