limzz has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl/Unix question; returning grep as a boolean and returning a match
by davido (Cardinal) on Jun 03, 2011 at 19:24 UTC | |
|
Re: Perl/Unix question; returning grep as a boolean and returning a match
by jwkrahn (Abbot) on Jun 04, 2011 at 00:13 UTC | |
|
Re: Perl/Unix question; returning grep as a boolean and returning a match
by graff (Chancellor) on Jun 04, 2011 at 00:40 UTC | |
|
Re: Perl/Unix question; returning grep as a boolean and returning a match
by Sandy (Curate) on Jun 03, 2011 at 19:22 UTC |