Searching for functions in Perl code
    Steve Bertrand 
    steve at ipv6canada.com
       
    Thu May 20 01:39:11 UTC 2010
    
    
  
This is more of a handy how-to than it is a question. A permanent
'howto' as it were.
A Perl project I'm working on contains 457 functions (ie. subroutines
(ie methods)), and even though I have documentation for all of them,
sometimes it is handy to have a list in front of me.
This is how I produce the list of all sub-routines within all module
files, which includes the module name and sub.
% grep -E -r "sub \w+ {" * | grep -v svn | awk '{FS=":"} \
{print $1, " ", $2}' | awk '{FS=" "} {print $1, " ", $3}'
...adapted to pull subs from a single file:
% cat lib/ISP/User.pm | grep -E "sub \w+ {" | awk '{print $2}'
For efficiency, and so I can remember more readily, my request is for
golf, particularly adaption to a Perl one-liner ;)
Cheers,
Steve
    
    
More information about the freebsd-questions
mailing list