Hello,
I made a program that traverses a directory listing all the files in it and in 
it's sub directories..

root@pacman:/home# cat list_dir

#!/usr/bin/perl -w



use 5.010;

use strict;




sub list_dir {

    say "Entring directory $_[0]";

    chdir $_[0]

        or die "$_[0]: $!\n";



    chomp(my $pwd = `pwd`);

    foreach my $entry (glob "*") {

        if (-d $entry) {

            list_dir($entry);    # Do not work without ()

        } else {

            say "$pwd/$entry";

        }

    }

    say "Leaving directory $_[0]";

}

list_dir $ARGV[0];
--

But it appears to break in the -d test of the subdirectory 'linux':

root@pacman:/home# /bin/ls -l tessio2/Books

total 10744

-rw-r--r-- 1 root root 2412061 2011-02-16 21:14 802.1Q-2005.pdf

-rw-r--r-- 1 root root  273110 2011-02-16 21:14 Artigo_SNMP.pdf

drwxr-xr-x 4 root root    4096 2011-02-16 21:14 ASAP

-rw-r--r-- 1 root root 5016115 2011-02-16 21:14 BSD_and_LINUX_09_2010_.pdf

-rw-r--r-- 1 root root  356148 2011-02-16 21:14 crash-course.pdf

-rw-r--r-- 1 root root  266236 2011-02-16 21:14 frutas_na_alimentacao.pdf

drwxr-xr-x 2 root root    4096 2011-02-16 21:14 linux

-rw-r--r-- 1 root root 2605022 2011-02-16 21:14 Milan Kundera - a insustent?vel 
leveza do ser.pdf

-rw-r--r-- 1 root root   52717 2011-02-16 21:14 opencon06-culture.pdf

drwxr-xr-x 9 root root    4096 2011-02-16 21:14 Perl

drwxr-xr-x 2 root root    4096 2011-02-16 21:14 TMP
--

Here is the program output (note that it stops entering directories after it 
leaves ASAP):

root@pacman:/home# perl list_dir tessio2

Entring directory tessio2

/home/tessio2/bookmarks-2011-02-16.json

Entring directory Books

/home/tessio2/Books/802.1Q-2005.pdf

/home/tessio2/Books/Artigo_SNMP.pdf

Entring directory ASAP

Entring directory Dic

/home/tessio2/Books/ASAP/Dic/01.txt

/home/tessio2/Books/ASAP/Dic/pre.txt

Leaving directory Dic

/home/tessio2/Books/ASAP/Distc

Leaving directory ASAP

/home/tessio2/Books/BSD_and_LINUX_09_2010_.pdf

/home/tessio2/Books/crash-course.pdf

/home/tessio2/Books/frutas_na_alimentacao.pdf

/home/tessio2/Books/linux
   
/home/tessio2/Books/Milan Kundera - a insustentável leveza do ser.pdf

/home/tessio2/Books/opencon06-culture.pdf

/home/tessio2/Books/Perl

/home/tessio2/Books/TMP

Leaving directory Books

/home/tessio2/commands

/home/tessio2/concurso.pdf

/home/tessio2/Desktop

/home/tessio2/Documents

/home/tessio2/Downloads

/home/tessio2/examples.desktop

/home/tessio2/Music

/home/tessio2/perlish

/home/tessio2/Pictures

/home/tessio2/Public

/home/tessio2/Templates

/home/tessio2/tj-apt

/home/tessio2/tj-net

/home/tessio2/Videos

Leaving directory tessio2
--

Why the -d test of subdirectory 'linux' (and posterior directories) don't work?
Thanks for your time!




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


Reply via email to