Deutsch   English   Français   Italiano  
<ygaa55uajy7.fsf@akutech.de>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: Ralf Fassel <ralfixx@gmx.de>
Newsgroups: comp.lang.tcl
Subject: Re: File processing (was Event loop and http::geturl)
Date: Thu, 26 Jun 2025 12:14:24 +0200
Lines: 29
Message-ID: <ygaa55uajy7.fsf@akutech.de>
References: <103cf0h$1glgk$1@dont-email.me> <103d93c$1q263$1@dont-email.me>
	<103dm05$1svqt$1@dont-email.me> <103ffab$2b701$1@dont-email.me>
	<103g70o$2k78v$1@dont-email.me> <103gdlo$2lnei$1@dont-email.me>
	<103hem3$2ua8s$1@dont-email.me> <103hptq$30q4s$1@dont-email.me>
	<103i951$33lgp$1@dont-email.me> <103j0gi$3bup4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net 5V/KGZCYc0XPEet9ieqtUw9dEt3DIjQCOJVV5MiyVuynpxoS0=
Cancel-Lock: sha1:p7hxesxPl2S8sPLlZVv7+xITdpg= sha1:ngfKlMbeQZs+v9e4aXUFtSRmRic= sha256:9XxBqh+YRzBDsvZIIlkQFJGuXuuOalvDippkg6+23Rg=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

* Alan Grunwald <nospam.nurdglaw@gmail.com>
| My pseudo code is generally
>
| while !eof {
|     read a line
|     if line is not empty
|         do stuff
|     endif
| endwhile
>
| I used to be puzzled why I needed the test for non-emptiness. I never
| worked out why, nowadays I simply accept that's the way of things and
| do it.

If the read hits EOF, an empty line is returned which is not actually in
the file.  Depending on your data, this may or may not be a problem
(if you're not interested in empty lines in the data, then no problem).

Usually a better pattern for line-oriented data
on a channel in blocking mode is

  while {[gets $fd line] >= 0} {
    # line has been read, possibly empty
    ...
  }
  close $fd

HTH
R'