Newbie needs help on implementing directory walk

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
 
N

nobull

I found references to use File::Find, but I
could not make it work so I tried to make a replacement for it.

Boggle! "I couldn't progam by VCR so I decided to build one from
scratch".
Any help would be greatly appreciated.

Your script does not enable strictures and warnings.

I have found several mistakes that would have been picked up by
strictures or warnings in the first few lines. For example, you use
the values in the $_ and $curfile variables without first doing
anything that could set them.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top