EDIT: In the if statement, <TERM> was supposed to say $y. And yes davido, I've got strict and warnings on, this is just a small snippet, thanks for the heads up though.

Hi all, So I'm a newbie to Perl and Unix, I've been self teaching for a couple weeks. Up until now I've been able to find everything on my own, but I can't seem to find this with Google or whatnot. For the script I'm currently writing 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. The following is basically what I have now:

$x = `gzgrep $y <PATH>`; if !`gzgrep $y <PATH>`{ $x = `gzgrep -i $y <PATH>`; }

The if statement works, but I'm sure there's a way to do that without greping twice, I just can't figure out the syntax. The other thing I would like to do, is if the case insensitive grep finds a match, I want to set $y to whatever was matched (so if $y = aaa and it finds aaA, I want $y to equal $aaA). I think I know how to do this with regular expressions, but I feel there must be an easier way, and I would like to learn. Thanks in advance, and sorry if this is trivial.


In reply to 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.