PT> Hi, PT> Iam a beginner in perl.I have one question, PT> Iam trying to write one prog,in which i have to search for one word in a PT> file, PT> If I found that word,print next 4 lines. PT> PLs help me,how to write code. PT> cheers, PT> prasa.
something like this should do the trick: open FILE, "<filename"; # loop through all the lines in the file while (<FILE>) { # if the line we just read contains your word # then read the next four lines and print them if (/your_word/) { # loop four times (four lines) for (1..4) { # specify scalar here to ensure correct context print scalar <FILE>; } # end for } # end if } # end while close FILE; if you want to stop after you've found the word the first time, then add "last;" below "} # end for" we need to say "scalar" because otherwise perl will think that we want to print the whole of the file. "print" works in array context, and the angle brackets <> will return all the lines in array context. if we force it to scalar context it will only return the next line. hth, daniel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]