perhaps?#!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__
In reply to Re: regexp for finding all function calls
by Anonymous Monk
in thread regexp for finding all function calls
by marksman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |