in reply to Re: Re: Create a list of directories without . and ..
in thread Create a list of directories without . and ..

if (-d $_) && ($_ != '.') && ($_ != '..') {

This is invalid syntax (needs an extra set of parens) and the != operator is not the one you want for string equality tests. I think you meant:

if (-d and $_ ne '.' and $_ ne '..') {
-d uses $_ if no argument is given.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: Re: Create a list of directories without . and ..
by Anonymous Monk on Jun 05, 2002 at 04:15 UTC

    Hi. Still having trouble with this...I do not understand why calling "test.pl ." finds subdirs in the Products subdir if I run it there and pass "." as the arg but doesn't find them if I run it one level back (ie. CD ..)and pass "./Products" as the arg??

    This is true which ever of the two filter clauses I use.

    I hate being a "newbie" again.

    C:\www\NB.biz\html>type test.pl #!/usr/bin/perl -w use strict; use diagnostics; print $ARGV[0], "\n"; opendir(DIR, $ARGV[0] ) or die ".: $!"; #my @list = grep { -d and /^\.\.?/ } readdir(DIR); my @list = grep { -d $_ and $_ ne '.' and $_ ne '..'} readdir(DIR); closedir(DIR); print foreach ( @list ), "\n"; C:\www\NB.biz\html>test.pl . . cssgraphicsProducts C:\www\NB.biz\html>test.pl ./products ./products <<<< NO OUTPUT HERE??? C:\www\NB.biz\html>test.pl ./Products/ ./Products/ <<<< OR HERE???? C:\www\NB.biz\html>cd products C:\www\NB.biz\html\Products>../test.pl . . Books C:\www\NB.biz\html\Products>
    Thanks, NJ Sandever.