Perl Programming Question: Download Questions PDF
How do I generate a list of all .html files in a directory?
Answer:
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 "$filen";
}
#!/usr/bin/perl -w
opendir(DIR, ".");
@files = grep(/.html$/,readdir(DIR));
closedir(DIR);
foreach $file (@files) {
print "$filen";
}
Download Perl Programming Interview Questions And Answers
PDF
Previous Question | Next Question |
How do I do fill_in_the_blank for each file in a directory? | What is Perl one-liner? |