DEVFYI - Developer Resource - FYI

How do I generate a list of all .html files in a directory?

Perl Questions and Answers


(Continued from previous question...)

How do I generate a list of all .html files in a directory?

Here's a snippet of code that just prints a listing of every file in the current directory that ends with the extension .html:
#!/usr/bin/perl -w
opendir(DIR, ".");
@files = grep(/\.html$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
print "$file\n";
}

(Continued on next question...)

Other Interview Questions