You said:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.