-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Dec 2, 2008, at 11:51 AM, John W. Krahn wrote:

James Moser wrote:
On Dec 2, 2008, at 5:48 AM, Koti wrote:

I have a directory named "X" which has many sub directories
"Y","Z","W" and many files about 20 , and these sub directories also
contain some more sub directories and files in them and those sub
directories also contain more directories and files.

I want to read all the files that exists across all the  directors,
subdirectories (only files list)  and need to display .

i tried until 2 loops , but unable to complete the logic well on a
whole. can u help me if u have any idea ,
You might want to read up on recursion.   Try something like this:

use warnings;
use strict;


sub directory {
   my $directory = shift;
   opendir(DIR, $dir) || die "Unable to open the directory";

Don't you mean:

    opendir(DIR, $directory)


   @contents = readdir(DIR);
   close(DIR);
   foreach $listitem (@contents ) {
       if ( -d $listitem ) {

That won't work.

perldoc -f readdir


           print " It's a directory!\n";
directory($directory.'/'.$listitem); # This is recursion...
       }
       else {
           print $l2;

Where did $l2 come from?


It was from his original code... I was just rearranging it to help him "complete the logic". Like I said, I didn't debug or test it, it was for him to get the idea.

James Moser
[EMAIL PROTECTED]

There are 10 kinds of people in the world.
Those who understand binary, and those who do not.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkk1eI8ACgkQBNt7jTp4/nmvggCgmgFofwuOoGMiA68ON7Qwr+Qw
9OEAoKpcHdhCoijw218Pu+mvBAnL/FBw
=rSCb
-----END PGP SIGNATURE-----

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to