Hi Bill,

You can use "last"; i.e.:

#Code beings
open (IN, "<in.txt") || die;
open (OUT, ">out.txt") || die;
while (<IN>) {
last if /END/;
print OUT;
}
close (IN);
close (OUT);
#Code ends

I hope that helps.

Bill Akins wrote:

> Hi all,
> 
> I would like to read in a file and print out to a new file UNTIL I reach a
> key word in the file.
> 
> I tried something like
> 
> while (<>) {
> if !/KEYWORD/;
> print $ >> dest.txt;
> }
> 
> but that seems to copy all lines of the file except the one(s) contining
> KEYWORD.  How can I have this exit and close dest.txt when I reach the line
> containing KEYWORD?  Maybe
> 
> while (<>) {
> if /KEYWORD/;
> exit
> else print $ >> dest.txt;
> }
> 
> What would be the best approach?  Thanx for any help!


-- 
Ahmed Moustafa
[EMAIL PROTECTED] | http://pobox.com/~amoustafa


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to