Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: regexp for finding all function calls

by Anonymous Monk
on Jul 09, 2009 at 03:15 UTC ( #778464=note: print w/ replies, xml ) Need Help??


in reply to regexp for finding all function calls

Something along the lines of ...

#!c:\Perl\bin\perl.exe # # This recursively searches .pl and .pm files for parenthesized functi +on calls. # $ARG[0] specifies the initial directory, # $ARG[1] specifies the function name, # for example: # c:\alpha\adx gettext # use File::Find; use Perl6::Slurp; use strict; use warnings; # Prowl the drive looking for files named .pl and .pm find({ wanted => \&FindFunctionCalls__, follow => 0 } ,$ARGV[0]); exit; sub FindFunctionCalls__ { # Don't trace me # $File::Find::dir is the current directory name, # $_ is the current filename within that directory # $File::Find::name is the complete pathname to the file. return unless (m/\.p(l|m)$/i); return if (/^(p|s)\./); my($s_Function)=($ARGV[1]); # Slurp my $s_Code=slurp $File::Find::name, {}; my $Count; # ... and search for "$s_Function" if (my $Count=($s_Code=~s/(?:^|\W)$s_Function\W/$&/g)) { # $s_ +Function occurred at least once # Remove the "use statement;" if any print "\nFound $Count in $File::Find::name\n"; # Balanced parentheses: my $np; # The initial balance parentheses expression with an embed +ded set is: # $np=qr/\( ([^()] | (??{$np})) *\)/x; # and quoted strings are "(?:[^"]|\")*" and '(?:[^']|\')* +' or ('|")(?:[^\1]|\\1)*\1 so $np=qr/ \( + # The opening "(" (( + # We'll want this hence the capturing () '(?:[^']|\')*?' + # a single quote string | "(?:[^"]|\")*?" + # a double quote string | [^()] + # not a parentheses | (??{$np}) )*) \) + # and the closing ")" /x; # Find the body of the function calls my($s_CompleteCall,$s_Before); while ($s_Code =~ m/(?:^|\W)($s_Function\s*$np)/gos) { # H +ave the entire call! # The complete call is $s_CompleteCall=$1; # and line number is print 1+(($s_Before=$`)=~ tr/\n/\n/).": $s_CompleteCal +l\n"; }; }; }; # __END__
perhaps?


Comment on Re: regexp for finding all function calls
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (18)
As of 2014-08-27 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (238 votes), past polls