Re: Need to extract only the function name no brackets reqd.
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Fri, 30 Mar 2007 13:55:10 +0100
Nath, Alok (STSD) wrote:
Hi,
I have this program which extract function names from the files.
My only problem is I want to extract only the function names{no
brackets () needed } .
Currently its extract all words after word sub but it all
returns the parentheses after that.
my $fileLoc = "//opt//sva//perl//lib//" ;
my $funcCount = 0 ;
opendir (DIR, $fileLoc) || die "Cannot opendir $!" ;
my @libs = readdir(DIR) ;
open (RES, ">out.txt") || die "Cannot open out.txt : $!" ;
foreach (@libs){
if(/pm$/){
open(FILE, $fileLoc.$_) or die("Unable to open $!") ;
print RES "Inside file >> $_ \n" ;
while (<FILE>){
chomp ;
if (/sub/){
my $sub ;
my $subName ;
($sub, $subName) = split /\s+/ ;
# print RES $_ ."\n" ;
print RES $subName."\n" ;
$funcCount ++ ;
}
}
print "\n\n" ;
close(FILE) ;
}
}
print RES "Total Functions : $funcCount \n" ;
close RES ;
closedir DIR ;
Hi Alok
If you're going to sell Perl you should program to its strengths. I hope you
find the program below clearer. I wasn't sure whny you doubled the slashes in
the path, but I left them in case there was a good reason. Were you getting
confused about escaping backslashes?
Rob
use strict;
use warnings;
my $fileLoc = "//opt//sva//perl//lib//";
open RES, '>out.txt' or die "Cannot open out.txt: $!";
my $funcCount = 0;
chdir $fileLoc or die $!;
opendir DIR, '.' or die "Cannot open directory: $!";
while (my $file = readdir DIR) {
next unless $file =~ /\.pm$/;
open FILE, $file or die "Unable to open file: $!";
print RES "Inside file >> $file\n" ;
while (<FILE>) {
chomp ;
if (/sub\s+(\w+)/) {
print RES $1, "\n" ;
$funcCount++;
}
}
close FILE;
print RES "\n\n" ;
}
closedir DIR ;
print RES "Total Functions: $funcCount\n" ;
close RES;
.
- References:
- Need to extract only the function name no brackets reqd.
- From: Alok Nath
- Need to extract only the function name no brackets reqd.
- Prev by Date: Re: Perl versus other scripting language
- Next by Date: Re: how to pass double quotes in a url from CGI script
- Previous by thread: Need to extract only the function name no brackets reqd.
- Next by thread: Re: Need to extract only the function name no brackets reqd.
- Index(es):
Relevant Pages
|