Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl (http://www.velocityreviews.com/forums/f17-perl.html)
-   -   Newbie needs help on implementing directory walk (http://www.velocityreviews.com/forums/t24477-newbie-needs-help-on-implementing-directory-walk.html)

SD 10-10-2003 05:57 AM

Newbie needs help on implementing directory walk
 
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

nobull@mail.com 10-10-2003 11:46 AM

Re: Newbie needs help on implementing directory walk
 
satyrdragon@yahoo.com (SD) wrote in message news:<33bd6865.0310092157.51c52cdd@posting.google. com>...

> 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.


All times are GMT. The time now is 11:43 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.