My example is exactly the same as yours.
The only2 differances, mine doesn't do what you want it, and it doesn't use regsub.
You say mine changes the value of var, and add stuff too it.
Then look at your own. It may not add stuff to it, but instead changes somthing. In eccance, adding is a change.
If it is a real must, and you realy are too thick, here is my example again, using resubs.
Code: Select all
set sub "ppslim is <WORD>"
set word "cool"
proc test {} {
global sub word
regsub -all -- "<WORD>" $sub $word sub
puts stdout "$sub"
}
puts stdout "$sub"
test
puts stdout "$sub"
This will produce
Code: Select all
ppslim is <WORD>
ppslim is cool
ppslim is cool
When in your thinking, you want it to produce
Code: Select all
ppslim is <WORD>
ppslim is cool
ppslim is <WORD>
the command "regsub" uses the following format
regsub ?switches? expression input-string subtituation-spec varname
Switches = Items that can effect how the command interets the input-string or expression. EG, rather than substituting the first match, replace them all.
expression = The item within input-string that should be replaced (seeing as this is a regular expression command, you can use these here).
input-string = the string of text, that the substitutions should be made on.
substitution-spec = what should the matches be replaced with
varname = where do we store the new item
using this small rement of code
Code: Select all
set text "hello <WORD> all"
regsub -all -- "<WORD> $text "to" text
We can see, that the variable $text, should be searched for the text "<WORD>.
If found, it should be replaced with the text "to".
The end result should be saved to the variable text.
As such, this command overwrites the variable text, with a new one.
This is exactly the same as what is happening in yours.
You are overwriting you input string "http://<IP>:<PORT>/<CHANNEL>" with the value you want to send to the channel.
If, for example, the first time you run the script,
<IP> = 192.168.254.1
<PORT> = 24
<CHANNEL> = mirchelp (#mirchelp with the # removed, as you wished)
Then all works well, and the message is displayed correctly.
Next time the script is run, the input-string becomes "
http://192.168.254.1:24/mirchelp"
This is not want you want.
Now look at my prevous post, to see an example at how things should be done.