[Za-pm] behaviour of opendir
Dr Giancarlo Contrafatto
contrafa at biology.und.ac.za
Tue Aug 5 03:03:48 CDT 2003
Hi folks;
I have come across a weird behaviour on the part of "opendir" and
"readdir", which I can't understand. Maybe the experienced "gurus" have
figured out what is going on and may be able to clarify the issue.
Take the following code, which produces a hyperlinked list of
directories:
#!/usr/bin/perl
print "usual headers";
$input = shift;
$path = "some directory"; # or a value passed from something else
opendir(DIR, $path) || die();
@folder=readdir(DIR);
foreach $entry (@folder) {
print "<a href=some.cgi?string>$entry</a><br>";
}
So far as I can see, there's nothing wrong with it and it usually works
fine. Now, I've added a couple new directories to the $path folder and
opendir (or, maybe, readdir) fails to see them and insists in printing
the older list of folders in $path. Ownerships and privileges are fine
and the new directories are seen from the shell and the desktop file
manager. This happens under a browser environment as well as while
testing from the shell. Using a different function (open pipe) works
fine so that the following snippet prints all the directories (including
the new ones):
open(DIR, "ls $path |") || die();
@folder=<DIR>; # or while loop
foreach $entry (@folder) {
..........
Am I being daft, or is there a sensible reason as to why this should be
happening?
ciao
---
The surest way to success is sincerity. Once you can fake that, you've
got it made! A. Bloch
####################################################################
Dr. Giancarlo Contrafatto
School of Life and environmental Sciences
University of Natal, 4041, Durban, RSA
Tel: +27 031 2603336 contrafa at biology.und.ac.za
####################################################################
visit Darwin at http://contra.biology.und.ac.za/
More information about the Za-pm
mailing list