sparkyichi has asked for the wisdom of the Perl Monks concerning the following question:
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);
opendir (DIR, ".") or die "$!"; @dir = grep !/^\.\.?$/, readdir DIR; closedir DIR;
|
|---|
| 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 |