Nicholas G. Thornton asked:

> I have a program I'm working on that reads a text file and does stuff with it.
> Thing is I want to exit from the while(<FH>) loop prematurely if, say, the line
> is '__END__'. I can't figure out how to do this, exit and return don't work, any
> ideas?


My proposal: If there is a question (and even if it seems to be a silly one)
just answer it, and there is not that much void noise in this MacPerl list.
The simple answer is:

#############  Exiting a while loop ##############################
while (<DATA>)  {         ##  read line by line
  print uc($_);           ##  do something with each line
  last if m,__END__,  }   ##  and exit as soon as __END__ is seen
############ End of script; some data:  ##########################

__DATA__
aaa
bbb
ccc
and so on __END__
and some more
fff
ggg


Output will be:
AAA
BBB
CCC
AND SO ON __END__


Ronald's answer
   "try last"
was clear and right, but maybe it was a bit tooo short.

Does my script answer the discussion, or did I miss something??

Detlef



Reply via email to