Hi,

I have a script that uses File::Find to recursively access directories and their contents.

The problem that I am facing in this is that when I have a list of directories in a directory, the find is accessing directories in an unexpected manner. I do not know the reason why.

The code snippet of my script is:-

#!/usr/bin/perl -w use strict; use File::Find; find(\&wanted,'/root/data'); sub wanted { if ($_=~ /^CPU-MEM/){ chdir($_); my $dir=cwd(); my @files=<$dir/*>; my $count=@files; if($count<4){ system('/usr/bin/perl /root/scripts/a.pl'); system('/usr/bin/perl /root/scripts/b.pl'); } chdir(".."); } }

Now, I have a directory data in which if i copy three directories - dir1 dir2 dir3. The processing is happening in this order:-

dir3 dir1 dir2

I want the recursion to occur in the same order as they are available in the data directory since there are dates in the subdirectories of data which must be printed in that order.

Is it possible to make File::Find perform my job as i require it to? If yes, How?

Thanks in advance for ur time.


In reply to File::Find doubt by tc_blr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.