• Can I work with EOF

    From Cecil Westerhof@21:1/5 to All on Fri Nov 26 14:34:41 2021
    At the moment I have the following code:
    while {True} {
    yield
    if {-1 == [gets ${vmstat} line]} {
    break
    }
    showMessage $line True
    }

    Instead of True I would prefer to use:
    ! [eof ${vmstat}]

    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Schelte@21:1/5 to Cecil Westerhof on Fri Nov 26 15:36:36 2021
    On 26/11/2021 14:34, Cecil Westerhof wrote:
    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?

    No. Tcl has no way of knowing it has reached the end of a file until it
    tries to read past it.

    But similar to suggestions in the recent "How to prompt before get?"
    thread, you can make a helper proc, or do:

    while {[yield; gets $vmstat line] != -1} {
    showMessage $line True
    }

    Or similar to my response to your previous question, use coroutine::util:

    while {[coroutine::util gets $vmstat line] != -1} {
    showMessage $line True
    }


    Schelte.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Schelte on Fri Nov 26 16:10:45 2021
    Schelte <nospam@wanadoo.nl> writes:

    On 26/11/2021 14:34, Cecil Westerhof wrote:
    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?

    No. Tcl has no way of knowing it has reached the end of a file until it
    tries to read past it.

    But similar to suggestions in the recent "How to prompt before get?"
    thread, you can make a helper proc, or do:

    while {[yield; gets $vmstat line] != -1} {
    showMessage $line True
    }

    Or similar to my response to your previous question, use coroutine::util:

    while {[coroutine::util gets $vmstat line] != -1} {
    showMessage $line True
    }

    I like the last one. I will implement that one.

    Thanks again.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Cecil Westerhof on Fri Nov 26 15:07:11 2021
    Cecil Westerhof <Cecil@decebal.nl> wrote:
    Is there a way to get the eof triggered without the unsuccessful read?

    No, file streams operate by reporting EOF /after/ an attempt to read
    past EOF occurs. This is how the underlying OS file stream
    implementation operates. It is not a Tcl add on or issue at all.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Fri Nov 26 17:07:39 2021
    Am 26.11.2021 um 14:34 schrieb Cecil Westerhof:
    At the moment I have the following code:
    while {True} {
    yield
    if {-1 == [gets ${vmstat} line]} {
    break
    }
    showMessage $line True
    }

    Instead of True I would prefer to use:
    ! [eof ${vmstat}]

    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?


    Dear Cecil,

    it is not necessarily an unsuccessful read. Only a read instruction
    updates the eof indicator. If there appears eof in the read, it is
    updated. It must not be "unsuccessful" (means with empty result).

    Sorry for the details,
    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cecil Westerhof@21:1/5 to Harald Oehlmann on Fri Nov 26 20:05:55 2021
    Harald Oehlmann <wortkarg2@yahoo.de> writes:

    Am 26.11.2021 um 14:34 schrieb Cecil Westerhof:
    At the moment I have the following code:
    while {True} {
    yield
    if {-1 == [gets ${vmstat} line]} {
    break
    }
    showMessage $line True
    }
    Instead of True I would prefer to use:
    ! [eof ${vmstat}]
    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?


    Dear Cecil,

    it is not necessarily an unsuccessful read. Only a read instruction
    updates the eof indicator. If there appears eof in the read, it is
    updated. It must not be "unsuccessful" (means with empty result).

    Sorry for the details,

    No nee to apologise. The devil is in the details, so it does not hurt
    to know them.

    --
    Cecil Westerhof
    Senior Software Engineer
    LinkedIn: http://www.linkedin.com/in/cecilwesterhof

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to Cecil Westerhof on Fri Nov 26 13:11:46 2021
    On Friday, November 26, 2021 at 7:14:05 AM UTC-8, Cecil Westerhof wrote:
    Schelte <nos...@wanadoo.nl> writes:

    On 26/11/2021 14:34, Cecil Westerhof wrote:
    The problem is that the eof online is triggered after an unsuccessful
    read. I could change my break in a continue, but I do not see that as
    an improvement.
    Is there a way to get the eof triggered without the unsuccessful read?

    No. Tcl has no way of knowing it has reached the end of a file until it tries to read past it.

    But similar to suggestions in the recent "How to prompt before get?" thread, you can make a helper proc, or do:

    while {[yield; gets $vmstat line] != -1} {
    showMessage $line True
    }

    Or similar to my response to your previous question, use coroutine::util:

    while {[coroutine::util gets $vmstat line] != -1} {
    showMessage $line True
    }
    I like the last one. I will implement that one.

    This is just a comment about style. I prefer to look at tests like this positively (i.e. positive logic):

    while {[gets $vmstat line] >= 0} {...}

    This test says "keep processing lines that have content or zero length (i.e. null content), *everything* else is an exit condition." In other words, all negative lengths are considered, not just the ?arbitrary? -1.

    Again, this is just my style preference.

    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)