1> around 500 files having extension .rex,.fmt,.pld which are stored in @onlyfiles 2> around 8000 keywords which are stored in the array @keyword

I want to search all the 8000 keywords in all the 100 files. If any keyword is found in a file, it ll change it's extension from .rex to .txt,.fmt to .fmg and so on and the file name will be put into the database.

But it is taking too long time ..Could you please someone help me to finetune the code so that it could run faster.. Or else can i use multithreading for this and how to do this.

Additionally, remove use Data::Dumper, as that module was only used for testing purposes.

The script creates a hash of your keywords. It then reads all files' lines, splitting each line into "words." The grep checks whether any one of those words are a keyword. (This check is case-insensitive; remove the two lcs if you need it to be case-sensitive.) If a keyword is found, the file is closed, the file extension is changed in the array, and the next file is processed.

Re: [millan] greping a large no keywords in large no of files
[In reply to]

Can't Post

Here is one more method to consider. I expect 'any' to be faster than grep because it can terminate as soon as it finds one match. By using an array of Regex's, they only have to be compiled once. Even more time could probably be saved by combing groups of kewords (joined with '|' )in each regex. Slurping the files should be faster than reading line-by-line.

Re: [millan] greping a large no keywords in large no of files
[In reply to]

Can't Post

You're most welcome, millan!

lc $_ converts the contents of $_ to all lowercase, these contents coming from either your list of keywords or a file's line being split. This was done so case is not significant in your search for keywords. If case is significant, remove both lc.