I need to find a string in a file path, and if it's not found search again, but insensitive to cases. I don't make it case insensitive in the first place because that makes it take a lot longer, and I'm looping this many times.
That, along with fact that you're using gzgrep (to find stuff in presumably large compressed files), raises a variety of warning signals for me. First, case-insensitive search vs. case-sensitive shouldn't have such a big impact on the run-time of gzgrep itself, though it might have a major impact on your perl script, depending on how many matches you get one way vs. the other way.
Because you're using backticks, perl has to allocate memory for all the output, so if there's a lot, your script likely to slow down a lot. jwkrahn's suggestion above will avoid that problem, and will also do what needs to be done in a single pass over the input, which is bound to be faster than going over the input twice.
As for "looping this many times", I'm not sure what you mean by that. If it means going over the same input many times to look for different patterns, you can adapt jwkrahn's approach to combine multiple matches in a single pass over the file, either using a more elaborate regex (with capturing parens so you can tell what matched), or extending the sequence of elsif matches on each input line. Either way is likely to be faster than reading the same input over and over for each condition.
In reply to Re: Perl/Unix question; returning grep as a boolean and returning a match
by graff
in thread Perl/Unix question; returning grep as a boolean and returning a match
by limzz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |