• Clock scan issue

    From snosniv@21:1/5 to All on Tue Nov 1 08:17:01 2022
    My CSV file has the row data like this:

    "1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,

    So when I chop up the row into elements I get the timestamp as just:
    "1 November 2022 11:00:27"


    So I have to further remove the quotes to get clock scan with format to work, by using:
    set l1 [string length $my_DateTime]
    set my_DateTime [string range $my_DateTime 1 [expr $l1 - 2]]

    Is there a simpler way please?

    TIA Niv.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Tue Nov 1 17:14:40 2022
    * snosniv <[email protected]>
    | My CSV file has the row data like this:

    | "1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,
    |
    | So when I chop up the row into elements I get the timestamp as just:
    | "1 November 2022 11:00:27"

    Others have already pointed to tcllib::csv

    https://core.tcl-lang.org/tcllib/doc/trunk/embedded/md/tcllib/files/modules/csv/csv.md

    Use it to process your CSV input, and the quoting issue will go away.

    Other than that, check the "string trim" method

    https://www.tcl-lang.org/man/tcl8.6/TclCmd/string.htm#M47

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to snosniv on Tue Nov 1 16:53:29 2022
    snosniv <[email protected]> wrote:
    My CSV file has the row data like this:

    "1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,

    So when I chop up the row into elements I get the timestamp as just:
    "1 November 2022 11:00:27"


    So I have to further remove the quotes to get clock scan with format to work, by using:
    set l1 [string length $my_DateTime]
    set my_DateTime [string range $my_DateTime 1 [expr $l1 - 2]]

    Is there a simpler way please?

    Use the Tcllib CSV library. It handles the quirky quoting standard for
    CSV files which you are not handling with what appears to be your own
    custom attempt at parsing the CSV file..

    I.e.:

    package require csv
    package require struct::queue

    struct::queue q
    set fd [open csvfile.csv RDONLY]
    csv::readwqueue $fd q
    close $fd

    foreach row [q get [q size]] {
    # do things with each row here -- and any CSV escaping quotes will be
    # missing, but any quotes that actually form part of the data will be
    # present
    }

    Do note that the above hoovers the entire CSV into memory all at once. Depending on the size of the csv, you may or may not want to hoover it
    all in up front.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From snosniv@21:1/5 to Rich on Wed Nov 2 01:53:21 2022
    On Tuesday, 1 November 2022 at 16:53:33 UTC, Rich wrote:
    snosniv <[email protected]> wrote:
    My CSV file has the row data like this:

    "1 November 2022 11:00:27",156.0,24.2,15.7,131.6,13.6,7.0,

    So when I chop up the row into elements I get the timestamp as just:
    "1 November 2022 11:00:27"


    So I have to further remove the quotes to get clock scan with format to work, by using:
    set l1 [string length $my_DateTime]
    set my_DateTime [string range $my_DateTime 1 [expr $l1 - 2]]

    Is there a simpler way please?
    Use the Tcllib CSV library. It handles the quirky quoting standard for
    CSV files which you are not handling with what appears to be your own
    custom attempt at parsing the CSV file..

    I.e.:

    package require csv
    package require struct::queue

    struct::queue q
    set fd [open csvfile.csv RDONLY]
    csv::readwqueue $fd q
    close $fd

    foreach row [q get [q size]] {
    # do things with each row here -- and any CSV escaping quotes will be
    # missing, but any quotes that actually form part of the data will be
    # present
    }

    Do note that the above hoovers the entire CSV into memory all at once. Depending on the size of the csv, you may or may not want to hoover it
    all in up front.

    Thanks for the pointer to the CSV lib. & tips on usage.

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