[vienna.pm] Kochbuch und for/while
Roland Bauer
Roland.Bauer at mediaprint.at
Fri Apr 7 07:50:50 CDT 2000
* * * vienna-pm-list * * *
Nachtrag zum Directorylisting-Beispiel ...
Ueber die Nuetzlichkeit des Kamels und des
Kochbuchs wurde hier schon einmal geschrieben.
Beweis der Anfaengertauglichkeit:
#------------------------------------------------------------------------------
Rezept 9.5. Processing All Files in a Directory
PROBLEM:
You want to do something to each file in a particular directory.
SOLUTION:
Use opendir to open the directory and then readdir to retrieve
every filename:
opendir(DIR, $dirname) or die ""can't opendir $dirname: $!";
while (defined($file = readdir(DIR))) {
# do something with "$dirname/$file"
}
closedir(DIR)
#------------------------------------------------------------------------------
Und dann folgt eine ausfuehrliche Diskussion.
Kochbuch = "Perl Cookbook" von Tom Christiansen/Nathan Torkington
Schoene Gruesse
Roland
P.S. Aber waere wieso while und nicht for?
opendir(DIR, $dirname) or die ""can't opendir $dirname: $!";
for (readdir(DIR) {
# do something with "$dirname/$file"
}
closedir(DIR);
###
You are subscribed to vienna-pm-list as "Roland Bauer" <Roland.Bauer at mediaprint.at>
http://www.fff.at/fff/vienna.pm/
More information about the Vienna-pm
mailing list