• list element in braces followed by "p" instead of space

    From Luc@21:1/5 to All on Mon Jan 16 21:15:39 2023
    Code:

    ----------------------------------------------
    set chan [pop3::open -socketcmd tls::socket server.com user password]

    set popuidl [::pop3::uidl $chan]
    if {[llength $popuidl] == 0} {
    puts "nothing"
    exit
    }
    puts $popuidl
    set popcount [expr [llength $popuidl] / 2]
    if {$popcount == 1} {puts "$popcount message\n"}
    if {$popcount > 1} {puts "$popcount messages\n"}

    set fp [open /path/to/file.txt "a"]
    foreach i [seq 1 1 $popcount] {
    set popmsg [::pop3::top $chan $i 1000]
    array set ::messages "$i $popmsg"
    puts $fp "popcheck begin"
    puts $fp $popmsg
    puts [llength $popmsg]
    puts $fp "popcheck end"
    }
    close $fp

    parray ::messages
    ----------------------------------------------

    Note: seq is a proc. With 3 messages,
    [seq 1 1 $popcount] returns "1 2 3". It's a home-brewn
    Tcl version of the Unix shell command.

    Two problems, or rather the same problem twice.
    I keep getting this error:

    ----------------------------------------------
    list element in braces followed by "p" instead of space
    while executing
    "array set ::messages "$i $popmsg""
    ("foreach" body line 3)
    invoked from within
    "foreach i [seq 1 1 $popcount] {
    set popmsg [::pop3::top $chan $i 1000]
    array set ::messages "$i $popmsg"
    puts $fp "popcheck begin"
    puts $fp $pop..."
    (file "checkmail.tcl" line 19)
    Compilation failed.
    ----------------------------------------------

    By elimination, I see that two lines cause the error:

    array set ::messages "$i $popmsg"

    puts [llength $popmsg]

    If I remove the first line, the second one triggers the
    exact same error.

    Why?

    Note that 'puts $fp $popmsg' correctly appends the
    entire header and message to /path/to/file.txt.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to Luc on Tue Jan 17 03:40:38 2023
    Luc <[email protected]> wrote:
    Code:
    set fp [open /path/to/file.txt "a"]
    foreach i [seq 1 1 $popcount] {
    set popmsg [::pop3::top $chan $i 1000]
    array set ::messages "$i $popmsg"
    puts $fp "popcheck begin"
    puts $fp $popmsg
    puts [llength $popmsg]
    puts $fp "popcheck end"

    Two problems, or rather the same problem twice.
    I keep getting this error:

    ----------------------------------------------
    list element in braces followed by "p" instead of space
    while executing
    "array set ::messages "$i $popmsg""
    ("foreach" body line 3)
    invoked from within
    "foreach i [seq 1 1 $popcount] {
    set popmsg [::pop3::top $chan $i 1000]
    array set ::messages "$i $popmsg"
    puts $fp "popcheck begin"
    puts $fp $pop..."
    (file "checkmail.tcl" line 19)
    Compilation failed.
    ----------------------------------------------

    Why?

    Array set expects as its second argument a list. You are handing it a
    string comprised of the concatenation of $i and the contents of
    $popmsg. When you use a string in a context that expects a list, Tcl
    attempts to convert that string into a list -- but if the string
    contains the wrong special characters in the wrong places, that
    conversion into a list fails with exactly this error.

    You want to do this for your array set:

    array set ::messages [list $i $popmsg]

    Then, array set receives a proper list, containing two elements, and
    Tcl will not try to convert the contents of the $popmsg string into a
    list.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From heinrichmartin@21:1/5 to Rich on Wed Jan 18 00:23:48 2023
    On Tuesday, January 17, 2023 at 4:40:42 AM UTC+1, Rich wrote:
    Luc wrote:
    Code:
    [...]

    Why?

    [...]

    You want to do this for your array set:

    array set ::messages [list $i $popmsg]

    ... which should be the same as "set ::messages($i) $popmsg" to state the obvious.

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