[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Perl and recursion...






On Tue, November 15, 2005 15:26, Jay Hannah wrote:

> Can you paste the output of the program to the list? That would help
me

> understand what's happening.



Sure thing.  Here is the output with line numbers.



Lines 1 through 10 are the files in /tmp/base that I am testing
with.  As you can see, there are files 1 through 4 in /tmp/base, and
files A through C in /tmp/base/dir1.



     1        $
find /tmp/base -print

     2       
/tmp/base

     3       
/tmp/base/file1

     4       
/tmp/base/file2

     5       
/tmp/base/dir1

     6       
/tmp/base/dir1/fileA

     7       
/tmp/base/dir1/fileB

     8       
/tmp/base/dir1/fileC

     9       
/tmp/base/file3

    10       
/tmp/base/file4



When I run the script with recursion enabled, it does dive into the
/tmp/base directory and finds each "fileA" through
"fileC".  Unfortunatly, when it gets to the end of that
directory, it falls through and the script ends.



    12        $ perl
testr.pl

    13        Adding
"/tmp/base/file1".

    14        Adding
"/tmp/base/file2".

    15        Diving
into "/tmp/base/dir1".

    16        Adding
"/tmp/base/dir1/fileA".

    17        Adding
"/tmp/base/dir1/fileB".

    18        Adding
"/tmp/base/dir1/fileC".

    19        Done.

    20        $



If I comment out the actual recursive call to the subroutine, I can see
that it still finds the /tmp/base/dir1, and it continues as expected:



    23        $ perl
testr.pl 

    24        Adding
"/tmp/base/file1".

    25        Adding
"/tmp/base/file2".

    26        Diving
into "/tmp/base/dir1".

    27        (recursive
call commented out.)

    28        Adding
"/tmp/base/file3".

    29        Adding
"/tmp/base/file4".

    30        Done.

    31        $ 





> Recursion is tricky. If it was working what were you wanting to

> actually do to each file/dir you found?



What I want it to step through all the files and directories given the
base directory to start in.  I've attached the script (testr.pl.AAA)
if anyone wants to play with it.  Just save and rename it, I made it
.AAA so the anti-virus programs won't try to strip it off as an attached
script.



I haven't had time, but I believe Theodore Kasteres' idea of puting the
files/directores into an array and working from the array might be the way
I attack this.



Dan



- - - -

"Wait for that wisest of all counselors, time." -- Pericles

"I do not fear computer, I fear the lack of them." -- Isaac
Asimov

GPG fingerprint:6FFD DB94 7B96 0FD8 EADF 2EE0 B2B0 CC47 4FDE 9B68



Attachment: testr.pl.aaa
Description: Binary data