Curious eval or lreplace issue in tcl proc

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Curious eval or lreplace issue in tcl proc

  • Creator
    Topic
  • #54119
    Mike Strout
    Participant

      I have a kill proc that identifies a bad value in a message, kills the message then sends contents of the message to some users via email so they can fix the problem. It is a very simple script, but it is wearing me out as the Cloverleaf “Testing” results don’t match what actually happens when I resend an example message. Here is the code snippet.

      if { ! [ string equal [ string range $csn 0 2 ] “400” ] } {

         set DISP “KILL”

         lreplace $segments 6 6 “”

         eval { exec echo [ join $segments “rn” ] | mailx -s “Message Subject” $email }

      }

      I use lreplace to remove the 7th item in the list because it is an embedded PDF that doesn’t need to be sent.

      If I put “echo [ join $segments “rn” ]” after lreplace and run the script, the PDF is stripped and the email that is generated doesn’t have it. However after reloading the tps into the thread Network Monitor, and resending the same message I used to test with, the PDF is sent in the email. If I change the [ join $segments “rn” ] to “grrr rn”, reload and resend, the email correctly sends “grrr” and the crlf.

      Me=stumped

    Viewing 6 reply threads
    • Author
      Replies
      • #80230
        Mike Strout
        Participant

          Ok, I solved my problem, but would still like to know why the original didn’t work. Here is what I did…

          Old:

          Code:

          if { ! [ string equal [ string range $csn 0 2 ] “400” ] } {
            set DISP “KILL”
            lreplace $segments 6 6 “”
            eval { exec echo [ join $segments “rn” ] | mailx -s “Message Subject” $email }
          }

          New:

          Code:


          if { ! [ string equal [ string range $csn 0 2 ] “400” ] } {
            set DISP “KILL”
            set msgbody [ lreplace $segments 6 6 “” ]
            eval { exec echo [ join $msgbody “rn” ] | mailx -s “Message Subject” $email }
          }

          Grrrr

          Mike

          <

        • #80231
          Jim Kosloskey
          Participant

            Mike,

            Well I cannot explain what you experienced but the lreplace provides a new modified list it does not change the list being referenced in the lreplace.

            So I would not expect your old code to work the way you intended and would not be surprised it did not.

            As to why it apparently worked in the tester and not in the engine all I can say is I don’t use the tester for TPS procs because in my experience the results were not always the same as what I would get in the engine – and it is so simple to test in the engine anyways.

            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

          • #80232
            Rob Abbott
            Keymaster

              If you have a reproducible case where the testing tool is not behaving the same as the engine – please send to support!  We’ve identified a few of these gaps over the past few releases and want to get any remaining differences solved.  Thanks!

              Rob Abbott
              Cloverleaf Emeritus

            • #80233
              Kevin Kinnell
              Participant

                Jim Kosloskey wrote:

                Mike,

                Well I cannot explain what you experienced but the lreplace provides a new modified list it does not change the list being referenced in the lreplace.

                Actually, Jim, you nailed it right there.  When Mike set msgbody he captured the changed list, so the changes didn’t just disappear.

                Kevin Kinnell | Senior Interface Programmer | Hattiesburg Clinic

              • #80234
                Mike Strout
                Participant

                  Kevin Kinnell wrote:

                  Actually, Jim, you nailed it right there.

                • #80235
                  Kevin Kinnell
                  Participant

                    Mike Strout wrote:

                    After a little more research, it seems that one needs to assign the result of lreplace to a variable for it to be saved.

                    Not correct

                    lreplace $segments 6 6 “”

                    Correct

                    set segments [ lreplace $segments 6 6 “” ]

                    The quickest way to tell what kind of command you’ve got is to see if the syntax expects a variable, or the contents of a variable.  If it says

                    Code:

                    cmd $foo ; # to save this you want  % set foo [cmd $foo]

                    it will require a set to save the results, if it says

                    Code:

                    cmd foo

                    it is directly manipulating the contents of the variable.

                    Getting the interpreters right in the testing tool is an amazing feat, and the tool has just been getting better over time.  But I wouldn’t use “what works in the testing tool” as a guide to syntax, yet.

                  • #80236
                    Jim Kosloskey
                    Participant

                      Mike,

                      Rob Abbott requested anyone who sees a difference between the testing tool and the engine report it.

                      It would be great if you could do that.

                      Since I don’t use the Tcl tester I won’t be able to report differences.

                      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                  Viewing 6 reply threads
                  • The forum ‘Cloverleaf’ is closed to new topics and replies.