----- Original Message ----- From: "FlashMX" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, November 25, 2004 8:31 AM
Subject: re: Using built in Grep


>
> I need to search for a certain string in a datafile and execute some other
code if a match is found.
>
> Do I have to read in the file before I can perform a grep? I thought the
grep works like it would from a command line?
>
> grep "string to search" <FILENAME>
>

This will do what you're asking:

open FILE "<somefile" or die "Can't open somefile: $!";
print grep /somestring|someotherstring/i, <FILE>;

This is probably better, though:

while ($line = <FILE>) {
    if ($line =~ /somestring|someotherstring/i) { print $line }}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to