[Za-pm] behaviour of opendir: reply to Oskar's reply

Dr Giancarlo Contrafatto contrafa at biology.und.ac.za
Wed Aug 6 07:46:56 CDT 2003


On Wed, 2003-08-06 at 14:25, Oskar Pearson wrote:
> 
> A couple of thoughts here. First off, the code looks fine - it shouldn't
> be doing strange things like this.
> 
> Normally I do something like this:
> #!/usr/bin/perl -w
> use strict;
> my $path = "/tmp";
> opendir(DIR, $path) || die("Cannot opendir: $!");
> foreach my $entry (readdir(DIR)) {
>         print "$entry\n";
> }
> 
> 
> So, I think the reason you've not got any answers (at least on the list)
> is that something is very strange :)

Hehehe! Yes, that's why I thought it'd be worth bring it up.

> 
> Here are some possibilities:
> 
> 1) are you doing this in an nfs mounted directory? I've seen caching
> that sometimes returns old results in NFS. This would explain why you
> get it in all cases (not just from a web page).

Yep, somewhat. This came out of an exchange I've had with Spike (which I
clean forgot to send to the list). As a matter of fact, my testing
environment on my home machine is a little strange. I run the script
from a RAID drive formated as ext3 but the data that the cgi has to work
on, are on an ext2 partition on the same drive. I have the sneaky
feeling .....
I'll test this within the next couple of days.

> 
> 2) Are you doing this in mod-perl? If so, it's perhaps possible that
> one or more variables isn't being cleared out when you hit the page
> the second time. In the simple example above this is less likely,
> but if it's just a "for example case" then perhaps this is the problem.
> You might want to try giving everything a defined scope, and using
> variables to hold the directory name:
> 
> #!/usr/bin/perl -w
> 
> use strict;
> my $path = "/tmp";
> 
> {
> 	# scoped to ensure limited lifetime
> 	my $dir;
> 	opendir($dir, $path) || die("Cannot opendir: $!");
> 	foreach my $entry (readdir($dir)) {
> 		print "$entry\n";
> 	}
> }

Right ... I think I see what you mean. Except that I'm not running it in
mod-perl.

> Please let us know the results!

Will do. Thanks.

ciao

-- 
the order of the links was changed but the chain remained a chain.
Gianni Rodari
####################################################################
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