I have a problem, I hope someone can help with ...
I have a foreach loop that executes the backticks command at each iteration, for example, greping in the directory for the string (as shown below, it is much easier to explain my question).
my @folderList = ("/home/bigfolder", "/home/hugefolder", "/home/massivefolder"); my @wordList = ("hello", "goodbye", "dog", "cat"); foreach my $folder (@folderList) { foreach my $word (@wordList) { print "Searching for this $word in this $folder\n"; my @output = `grep -R $word $folder`;
The problem I am facing:
If the folder in which the backticks grep command is executed is especially large or the array of words to check is especially large, then the backticks command can take several hours (this is normal).
But what I want to do is to exit the inner loop (i.e. when the word is copied to the folder) and go to the next iteration if it takes a long time when the user presses a key on the keyboard or, for example, enter the word " next "or" exit ".
I know that if I had not used backticks, I could easily break out of the normal loop using something like the following (but the logic of this obviously does not work when callbacks / system call are involved):
use strict; use warnings; use Term::ReadKey; my $n = 0; while () { print '.'; last if ReadKey(-1); $n++; } print $n;
There may be a simple solution that I skip, but I never had to do this before, so your help is much appreciated, thanks
source share