develooper Front page | perl.beginners | Postings from July 2003

opendir question

Thread Next
From:
Peter Fleck
Date:
July 29, 2003 10:26
Subject:
opendir question
Message ID:
a05210606bb4c5c8e6514@[128.101.204.106]
This isn't 'production' code. I'm playing with this to get ready to 
use the commands in a project. That's why I'm doing the same thing in 
two different ways.

I have two ways of of getting a list of file names below, working 
with opendir and readdir. The second method doesn't work if the first 
method is active. Commenting out the first segment gets the second 
segment to work. Reversing the order also of the methods also sees 
the first one only working.

What I would guess is that I can only use the 'readdir' once in a 
script. What's that about?

Thanks.

opendir(DIR, $dirname) or die "can't opendir $dirname: $!";

my @filelist = readdir(DIR);
print "\@filelist: @filelist\n";

while (my $file = readdir(DIR)) {
     print "$file\n";
}

closedir(DIR);

-- 
Peter Fleck
Webmaster | University of Minnesota Cancer Center
Dinnaken Office Bldg.
925 Delaware St. SE
Minneapolis, MN  55414
612-625-8668 | fleck004@umn.edu | www.cancer.umn.edu
Campus Mail: MMC 806

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About