[Perl] Finding Files, The Fun And Elegant Way

Posted by Artem Russakovskii on April 8th, 2009 in Awesomeness, Linux, Perl, Programming, Tutorials

Updated: October 6th, 2009

No matter what programming language you use, there comes a time when you need to search for a file somewhere on the file system. Here, I want to talk about accomplishing this task in Perl. There are many ways of doing so, most of them boring, but I want to discuss the fun and elegant way – using File::Find::Rule.

Let me briefly discuss some of the other methods first.


Using glob() (or <>, TODO verify) you can find files in a single directory, using only the limited shell wildcard support. For example,

my @files = glob("tmp*");

I prefer glob() to <> because glob()'s parameters can be more than just text (for ex functions) while <> treats everything