Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Newbie needs help on implementing directory walk

Reply
Thread Tools

Newbie needs help on implementing directory walk

 
 
SD
Guest
Posts: n/a
 
      10-10-2003
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,; # 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
 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      10-10-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (SD) wrote in message news:<(E-Mail Removed). 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
implementing python's os.walk Brad Volz Ruby 5 12-17-2008 03:35 AM
os walk() and threads problems (os.walk are thread safe?) Marcus Alves Grando Python 7 11-14-2007 02:30 PM
Walk thru each subdirectory from a top directory silverburgh.meryl@gmail.com Python 11 03-02-2007 09:33 AM
DVD Verdict reviews: WALK THE LINE, JARHEAD, WALK THE LINE: TWO-DISC COLLECTOR'S EDITION, and more! DVD Verdict DVD Video 0 03-20-2006 09:19 AM
Just want to walk a single directory SB Python 3 01-15-2006 10:16 PM



Advertisments