Newbie needs help on implementing directory walk

Discussion in 'Perl' started by SD, Oct 10, 2003.

  1. SD

    SD Guest

    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
     
    SD, Oct 10, 2003
    #1
    1. Advertising

  2. SD

    Guest

    (SD) wrote in message news:<>...

    > 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.
     
    , Oct 10, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SB
    Replies:
    3
    Views:
    322
    Tim Roberts
    Jan 15, 2006
  2. Replies:
    11
    Views:
    433
    Peter Otten
    Mar 2, 2007
  3. Marcus Alves Grando
    Replies:
    7
    Views:
    487
    Marcus Alves Grando
    Nov 14, 2007
  4. Steve Holden
    Replies:
    0
    Views:
    496
    Steve Holden
    Feb 26, 2009
  5. Brad Volz

    implementing python's os.walk

    Brad Volz, Dec 16, 2008, in forum: Ruby
    Replies:
    5
    Views:
    378
    Brad Volz
    Dec 17, 2008
Loading...

Share This Page