S
SD
Hi,
This is my very first Perl program.
I have a directory full of hundreds of files in different depths. I
need to figure out every occurrance of a string (ABCDnnnn where nnnn
is 1-9999) on html files among them and list those files that have
them and what they are. I have created a parser that finds the strings
(now, dont laugh, it works although its not cool - everyone has to
start sometimes).
But how do I do treewalk ? I found references to use File::Find, but I
could not make it work so I tried to make a replacement for it. It
does not work either - interpreter is not very helpful because only
thing it says is that there is an error on line
And to make things worse, this is Windows
Any help would be greatly appreciated.
# Name: parseEAReqs.pl
# perl parser for getting references to absolute pages containing
requirement definitions
#
my $rootdir = "u:\\EADoc";
my $curdir = "nodir";
my $req = "noreq";
opendir(IMD, $rootdir) or die "Cant open directory";
while (defined($file = readdir(IMD))) {
print $file, "\n";
}
if (/html/ {
# inner parser for finding the requirement and file
open(INFILE, $curfile) or die "Cant open file";
while (<INFILE>) {
if (/requirement: MONO/ && /Header/ && /class/) {
print "$_"; # whole
string
print "" while /(requirement: )/cgs;
my $npos = pos; # start pos
print "\nStarting Pos of req=", $npos, "\nRequirement ID:";
my $req = substr($_, $npos,8); # now contains ABCDnnnn with
possible <
print $req, ":\n";
print "" while /(<)/cgs; # Parse off all from < onwards
my $mpos = pos;
print "End Position of Req+1=", $mpos;
my $slen = $mpos - $npos -1;
print "\nRequirement Length=", $slen, "\n";
my $req = substr($_, $npos, $slen); # now contains ABCDnnnn
print $curfile . "," , $req, "\n";
}
}
close(INFILE);
}
closedir(IMD);
SD
This is my very first Perl program.
I have a directory full of hundreds of files in different depths. I
need to figure out every occurrance of a string (ABCDnnnn where nnnn
is 1-9999) on html files among them and list those files that have
them and what they are. I have created a parser that finds the strings
(now, dont laugh, it works although its not cool - everyone has to
start sometimes).
But how do I do treewalk ? I found references to use File::Find, but I
could not make it work so I tried to make a replacement for it. It
does not work either - interpreter is not very helpful because only
thing it says is that there is an error on line
And to make things worse, this is Windows
Any help would be greatly appreciated.
# Name: parseEAReqs.pl
# perl parser for getting references to absolute pages containing
requirement definitions
#
my $rootdir = "u:\\EADoc";
my $curdir = "nodir";
my $req = "noreq";
opendir(IMD, $rootdir) or die "Cant open directory";
while (defined($file = readdir(IMD))) {
print $file, "\n";
}
if (/html/ {
# inner parser for finding the requirement and file
open(INFILE, $curfile) or die "Cant open file";
while (<INFILE>) {
if (/requirement: MONO/ && /Header/ && /class/) {
print "$_"; # whole
string
print "" while /(requirement: )/cgs;
my $npos = pos; # start pos
print "\nStarting Pos of req=", $npos, "\nRequirement ID:";
my $req = substr($_, $npos,8); # now contains ABCDnnnn with
possible <
print $req, ":\n";
print "" while /(<)/cgs; # Parse off all from < onwards
my $mpos = pos;
print "End Position of Req+1=", $mpos;
my $slen = $mpos - $npos -1;
print "\nRequirement Length=", $slen, "\n";
my $req = substr($_, $npos, $slen); # now contains ABCDnnnn
print $curfile . "," , $req, "\n";
}
}
close(INFILE);
}
closedir(IMD);
SD