mlocate used as recursive file search in perl

Programming languages, Coding, executables, and scripting.
Post Reply
Posts: 10
Joined: 2009-07-24 18:47

mlocate used as recursive file search in perl

#1 Post by dormant »

I have a Perl script that needs to search a number of directories recursively for file names matching a pattern.

The files in these directories change slowly, so there is no need to actually search every time, which is slow. It also seems to be the only method in the Perl modules I can find and understand (I’m only an occasional Perl scripter.)

mlocate seems the best method, called as a system command in Perl. But there are a number of things I can’t see how to do.

1) The directory to be searched recursively is different for each call of the script. There are maybe 16 of these target directories and I don’t think I want to maintain a separate index database for each.

2) The target directory names are not unique enough, so it’s difficult to search using the directory name.

To illustrate, the script would want to search one of the following directories:

3) The file names that I am looking for have to match a complex expression. The file names are like this:


I want to match all the following :
- First two elements separated by _. In some cases there will be a choice of two strings to look for.
- The eight-character date string. Always comes after a .
- ext, which needs to be one of .gif, .png, .tif, .jpg

I’d appreciate any help or suggestions. I’ve been searching for help and examples, but I’m just getting confused. I don’t want to not use Perl because I’m updating a script I wrote a while back.

Post Reply