-d test stops working

Hello,=0AI made a program that traverses a directory listing all the files =
in it and in it's sub directories..=0A=0Aroot [at] pacman:/home# cat list_dir=0A=
=0A#!/usr/bin/perl -w=0A=0A=0A=0Ause 5.010;=0A=0Ause strict;=0A=0A=0A=0A=0A=
sub list_dir {=0A=0A say "Entring directory $_[0]";=0A=0A chdir $_[0]=
=0A=0A or die "$_[0]: $!\n";=0A=0A=0A=0A chomp(my $pwd =3D `pwd`)=
;=0A=0A foreach my $entry (glob "*") {=0A=0A if (-d $entry) {=0A=
=0A list_dir($entry); # Do not work without ()=0A=0A }=
else {=0A=0A say "$pwd/$entry";=0A=0A }=0A=0A }=0A=0A=
say "Leaving directory $_[0]";=0A=0A}=0A=0Alist_dir $ARGV[0];=0A--=0A=
=0ABut it appears to break in the -d test of the subdirectory 'linux':=0A=
=0Aroot [at] pacman:/home# /bin/ls -l tessio2/Books=0A=0Atotal 10744=0A=0A-rw-r-=
-r-- 1 root root 2412061 2011-02-16 21:14 802.1Q-2005.pdf=0A=0A-rw-r--r-- 1=
root root 273110 2011-02-16 21:14 Artigo_SNMP.pdf=0A=0Adrwxr-xr-x 4 root =
root 4096 2011-02-16 21:14 ASAP=0A=0A-rw-r--r-- 1 root root 5016115 2011=
-02-16 21:14 BSD_and_LINUX_09_2010_.pdf=0A=0A-rw-r--r-- 1 root root 356148=
2011-02-16 21:14 crash-course.pdf=0A=0A-rw-r--r-- 1 root root 266236 2011=
-02-16 21:14 frutas_na_alimentacao.pdf=0A=0Adrwxr-xr-x 2 root root 4096 =
2011-02-16 21:14 linux=0A=0A-rw-r--r-- 1 root root 2605022 2011-02-16 21:14=
Milan Kundera - a insustent?vel leveza do ser.pdf=0A=0A-rw-r--r-- 1 root r=
oot 52717 2011-02-16 21:14 opencon06-culture.pdf=0A=0Adrwxr-xr-x 9 root r=
oot 4096 2011-02-16 21:14 Perl=0A=0Adrwxr-xr-x 2 root root 4096 2011-=
02-16 21:14 TMP=0A--=0A=0AHere is the program output (note that it stops en=
tering directories after it leaves ASAP):=0A=0Aroot [at] pacman:/home# perl list=
_dir tessio2=0A=0AEntring directory tessio2=0A=0A/home/tessio2/bookmarks-20=
11-02-16.json=0A=0AEntring directory Books=0A=0A/home/tessio2/Books/802.1Q-=
2005.pdf=0A=0A/home/tessio2/Books/Artigo_SNMP.pdf=0A=0AEntri ng directory AS=
AP=0A=0AEntring directory Dic=0A=0A/home/tessio2/Books/ASAP/Dic/01.txt=0A=
=0A/home/tessio2/Books/ASAP/Dic/pre.txt=0A=0ALeaving directory Dic=0A=0A/ho=
me/tessio2/Books/ASAP/Distc=0A=0ALeaving directory ASAP=0A=0A/home/tessio2/=
Books/BSD_and_LINUX_09_2010_.pdf=0A=0A/home/tessio2/Books/cr ash-course.pdf=
=0A=0A/home/tessio2/Books/frutas_na_alimentacao.pdf=0A=0A/ho me/tessio2/Book=
s/linux=0A =0A/home/tessio2/Books/Milan Kundera - a insustent=E1vel levez=
a do ser.pdf=0A=0A/home/tessio2/Books/opencon06-culture.pdf=0A=0A /home/tess=
io2/Books/Perl=0A=0A/home/tessio2/Books/TMP=0A=0ALeaving directory Books=0A=
=0A/home/tessio2/commands=0A=0A/home/tessio2/concurso.pdf=0A =0A/home/tessio=
2/Desktop=0A=0A/home/tessio2/Documents=0A=0A/home/tessio2/Do wnloads=0A=0A/h=
ome/tessio2/examples.desktop=0A=0A/home/tessio2/Music=0A=0A/ home/tessio2/pe=
rlish=0A=0A/home/tessio2/Pictures=0A=0A/home/tessio2/Public= 0A=0A/home/tess=
io2/Templates=0A=0A/home/tessio2/tj-apt=0A=0A/home/tessio2/t j-net=0A=0A/hom=
e/tessio2/Videos=0A=0ALeaving directory tessio2=0A--=0A=0AWhy the -d test o=
f subdirectory 'linux' (and posterior directories) don't work?=0AThanks for=
your time!=0A=0A=0A

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
precheca123 [ Do, 17 Februar 2011 17:56 ] [ ID #2055462 ]

Re: -d test stops working

I just found the bug..=0A--=0A#!/usr/bin/perl -w=0A=0Ause 5.010;=0Ause stri=
ct;=0A=0A=0Asub list_dir {=0A=09my ($dir) =3D [at] _;=0A=09chdir $dir or die "$=
dir: $!\n";=0A=0A=09chomp(my $pwd =3D `pwd`);=0A=09say "$pwd/";=0A=0A=09for=
each my $entry (glob "*") {=0A=09=09# if entry is a directory, call list_di=
r on it=0A=09=09if (-d $entry) {=0A=09=09=09list_dir($entry);=09# Do not wo=
rk without "()"=0A=09=09} else {=0A=09=09=09say "$pwd/$entry";=0A=09=09}=0A=
=09}=0A=09chdir ".." or die "..: $!\n";=0A}=0A=0A# main program=0Adie "$0: =
missing operand\n" if [at] ARGV < 1;=0A=0Aforeach ( [at] ARGV) {=0A=09list_dir $_;=
=0A}=0A--=0A=0A'chdir ".." or die "..: $!\n"' is the bug fix.. :)=0A=0A> As=
sunto: -d test stops working=0A> Para: beginners [at] perl.org=0A> Data: Quinta-=
feira, 17 de Fevereiro de 2011, 14:56=0A> Hello,=0A> I made a program that =
traverses a directory listing all the=0A> files in it and in it's sub direc=
tories..=0A> =0A> root [at] pacman:/home# cat list_dir=0A> =0A> #!/usr/bin/perl =
-w=0A> =0A> =0A> =0A> use 5.010;=0A> =0A> use strict;=0A> =0A> =0A> =0A> =
=0A> sub list_dir {=0A> =0A> =A0 =A0 say "Entring directory $_[0]";=0A> =0A=
> =A0 =A0 chdir $_[0]=0A> =0A> =A0 =A0 =A0 =A0 or die "$_[0]: $!\n";=0A> =
=0A> =0A> =0A> =A0 =A0 chomp(my $pwd =3D `pwd`);=0A> =0A> =A0 =A0 foreach m=
y $entry (glob "*") {=0A> =0A> =A0 =A0 =A0 =A0 if (-d $entry) {=0A> =0A> =
=A0 =A0 =A0 =A0 =A0 =A0=0A> list_dir($entry);=A0 =A0 # Do not work without =
()=0A> =0A> =A0 =A0 =A0 =A0 } else {=0A> =0A> =A0 =A0 =A0 =A0 =A0 =A0 say=
=0A> "$pwd/$entry";=0A> =0A> =A0 =A0 =A0 =A0 }=0A> =0A> =A0 =A0 }=0A> =0A> =
=A0 =A0 say "Leaving directory $_[0]";=0A> =0A> }=0A> =0A> list_dir $ARGV[0=
];=0A> --=0A> =0A> But it appears to break in the -d test of the subdirecto=
ry=0A> 'linux':=0A> =0A> root [at] pacman:/home# /bin/ls -l tessio2/Books=0A> =
=0A> total 10744=0A> =0A> -rw-r--r-- 1 root root 2412061 2011-02-16 21:14=
=0A> 802.1Q-2005.pdf=0A> =0A> -rw-r--r-- 1 root root=A0 273110 2011-02-16 2=
1:14=0A> Artigo_SNMP.pdf=0A> =0A> drwxr-xr-x 4 root root=A0 =A0 4096 2011-0=
2-16 21:14=0A> ASAP=0A> =0A> -rw-r--r-- 1 root root 5016115 2011-02-16 21:1=
4=0A> BSD_and_LINUX_09_2010_.pdf=0A> =0A> -rw-r--r-- 1 root root=A0 356148 =
2011-02-16 21:14=0A> crash-course.pdf=0A> =0A> -rw-r--r-- 1 root root=A0 26=
6236 2011-02-16 21:14=0A> frutas_na_alimentacao.pdf=0A> =0A> drwxr-xr-x 2 r=
oot root=A0 =A0 4096 2011-02-16 21:14=0A> linux=0A> =0A> -rw-r--r-- 1 root =
root 2605022 2011-02-16 21:14 Milan=0A> Kundera - a insustent?vel leveza do=
ser.pdf=0A> =0A> -rw-r--r-- 1 root root=A0=A0=A052717 2011-02-16=0A> 21:14=
opencon06-culture.pdf=0A> =0A> drwxr-xr-x 9 root root=A0 =A0 4096 2011-02-=
16 21:14=0A> Perl=0A> =0A> drwxr-xr-x 2 root root=A0 =A0 4096 2011-02-16 21=
:14=0A> TMP=0A> --=0A> =0A> Here is the program output (note that it stops =
entering=0A> directories after it leaves ASAP):=0A> =0A> root [at] pacman:/home#=
perl list_dir tessio2=0A> =0A> Entring directory tessio2=0A> =0A> /home/te=
ssio2/bookmarks-2011-02-16.json=0A> =0A> Entring directory Books=0A> =0A> /=
home/tessio2/Books/802.1Q-2005.pdf=0A> =0A> /home/tessio2/Books/Artigo_SNMP=
..pdf=0A> =0A> Entring directory ASAP=0A> =0A> Entring directory Dic=0A> =0A=
> /home/tessio2/Books/ASAP/Dic/01.txt=0A> =0A> /home/tessio2/Books/ASAP/Dic=
/pre.txt=0A> =0A> Leaving directory Dic=0A> =0A> /home/tessio2/Books/ASAP/D=
istc=0A> =0A> Leaving directory ASAP=0A> =0A> /home/tessio2/Books/BSD_and_L=
INUX_09_2010_.pdf=0A> =0A> /home/tessio2/Books/crash-course.pdf=0A> =0A> /h=
ome/tessio2/Books/frutas_na_alimentacao.pdf=0A> =0A> /home/tessio2/Books/li=
nux=0A> =A0=A0=A0=0A> /home/tessio2/Books/Milan Kundera - a insustent=E1vel=
leveza=0A> do ser.pdf=0A> =0A> /home/tessio2/Books/opencon06-culture.pdf=
=0A> =0A> /home/tessio2/Books/Perl=0A> =0A> /home/tessio2/Books/TMP=0A> =0A=
> Leaving directory Books=0A> =0A> /home/tessio2/commands=0A> =0A> /home/te=
ssio2/concurso.pdf=0A> =0A> /home/tessio2/Desktop=0A> =0A> /home/tessio2/Do=
cuments=0A> =0A> /home/tessio2/Downloads=0A> =0A> /home/tessio2/examples.de=
sktop=0A> =0A> /home/tessio2/Music=0A> =0A> /home/tessio2/perlish=0A> =0A> =
/home/tessio2/Pictures=0A> =0A> /home/tessio2/Public=0A> =0A> /home/tessio2=
/Templates=0A> =0A> /home/tessio2/tj-apt=0A> =0A> /home/tessio2/tj-net=0A> =
=0A> /home/tessio2/Videos=0A> =0A> Leaving directory tessio2=0A> --=0A> =0A=
> Why the -d test of subdirectory 'linux' (and posterior=0A> directories) d=
on't work?=0A> Thanks for your time!=0A> =0A> =0A> =0A> =0A=0A=0A

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
precheca123 [ Fr, 18 Februar 2011 02:34 ] [ ID #2055463 ]

Re: -d test stops working

On 11-02-17 08:34 PM, Téssio Fechine wrote:
> I just found the bug..

If you're traversing directories, you should use File::Find. It's a
standard module that is installed with Perl. See `perldoc File::Find`
for details.

Also, to get a list of the standard modules and pragmatics:
perldoc perlmodlib


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Fr, 18 Februar 2011 17:37 ] [ ID #2055464 ]
Perl » gmane.comp.lang.perl.beginners » -d test stops working

Vorheriges Thema: IO::Socket::INET and 255.255.255.255
Nächstes Thema: threading perl 5.12