sparkyichi has asked for the wisdom of the Perl Monks concerning the following question:
I can't figure out why my directory listing with an if statement is not working the way I would expect. I want to exclude . and .. from showing up in the list so I did the following:
.
..
Why does it work one way and not the other?
B.T.W. I know that this works great:
Sparky
FMTEYEWTK
This prints out a complete list including . and .. I then tried the following to produce only a . and .. listing:my $dirname = '.'; opendir(DIR, $dirname) or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { if ($file ne '.' || $file ne '..'){print "$file\n";} } closedir(DIR);
And it works only printing the following:my $dirname = '.'; opendir(DIR, $dirname) or die "can't opendir $dirname: $!"; while (defined($file = readdir(DIR))) { if ($file eq '.' || $file eq '..'){print "$file\n";} } closedir(DIR);
.
..
Why does it work one way and not the other?
B.T.W. I know that this works great:
opendir (DIR, ".") or die "$!"; @dir = grep !/^\.\.?$/, readdir DIR; closedir DIR;
Sparky
FMTEYEWTK
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: If statements with . and .. filehandles.
by FoxtrotUniform (Prior) on Jun 18, 2002 at 20:22 UTC | |
Re: If statements with . and .. filehandles.
by tadman (Prior) on Jun 18, 2002 at 20:22 UTC | |
Re: If statements with . and .. filehandles.
by thelenm (Vicar) on Jun 18, 2002 at 20:22 UTC | |
Re: If statements with . and .. filehandles.
by tune (Curate) on Jun 18, 2002 at 21:09 UTC | |
by dsheroh (Monsignor) on Jun 18, 2002 at 23:49 UTC |
Back to
Seekers of Perl Wisdom