How to process every file in a directory that matches a pattern

by Nithya 2010-02-04 14:45:25

You can use the glob operator to get a list of all files in the current directory like this:

@files = glob("*.*");

foreach $file (@files) {
print "$file\n" if -f $file;
}


you can modify your glob pattern to get a list of all the filenames that end with .pl, like this:

# look for all *.pl files
@files = glob("*.pl");

foreach $file (@files) {
print "$file\n" if -f $file;
}

Tagged in:

683
like
0
dislike
0
mail
flag

You must LOGIN to add comments