This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

problem with switch [solved] now really ^^

Old posts that have not been replied to for several years.
Locked
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

problem with switch [solved] now really ^^

Post by De Kus »

Code: Select all

	set ip [lindex [fconfigure $sock -peername] 0]
	putdcc 12 "'$ip' '$::euroipchaos' '$::euroiploki'"
	if { [fconfigure $sock -error] == "" } {
		switch $ip {
			$::euroipchaos {
				set ::eurostatuschaos 1
				putdcc 12 "status chaos"
			}
			$::euroiploki {
				set ::eurostatusloki 1
				putdcc 12 "status loki"
			}
			default {putdcc 12 "noob"}
		}
	}
this is called on fileevent twice in a row each for the other ip.
here the partyline log caused by the debug code:
'62.109.138.138' '62.109.138.134' '62.109.138.138'
noob
'62.109.138.134' '62.109.138.134' '62.109.138.138'
noob
according to http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm this statement looks perfectly fine for me. I also tried to use ${::euroipchaos} which won't change anything. I also tried to use the variable via global and without :: within the switch structure, but still no change... it still calls default :(.
Last edited by De Kus on Mon Mar 14, 2005 7:56 pm, edited 4 times in total.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: problem with switch

Post by user »

De Kus wrote:according to http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm this statement looks perfectly fine for me.
According to http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M10 variable substitution is not performed between braces :wink:
try something like this

Code: Select all

switch -- whatever [list $var {code} $var2 {code} default {code}]
instead.
Have you ever read "The Manual"?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Re: problem with switch

Post by De Kus »

user wrote:According to http://tcl.tk/man/tcl8.5/TclCmd/Tcl.htm#M10 variable substitution is not performed between braces :wink:
try something like this

Code: Select all

switch -- whatever [list $var {code} $var2 {code} default {code}]
instead.
I only read this :D
The switch command can match against variables and not just literals, as shown here (the result is 2):

set foo "abc"
switch abc a - b {expr 1} $foo {expr 2} default {expr 3}
but to say it in short... user, you are my hero! that helped :).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

okay, that was a bit early... when I took a close look, I cannot get rid of this error now:
[00:34:25] #De_Kus# set errorInfo
Currently: invalid command name "bgerror"
Currently: while invoking
Currently: "unknown bgerror wrong # args: should be "switch ?switches? string pattern body ..."

Code: Select all

switch [list $ip $::euroipchaos {set ::eurostatuschaos 1} $::euroiploki {set ::eurostatusloki 1}]
did I understand something wrong again? :D

list seems not to be the problem, looks like its doing its job:
set list [list $ip $::euroipchaos {set ::eurostatuschaos 1} $::euroiploki {set ::eurostatusloki 1}]
for {set i 0} {$i < [llength $list]} {incr i} {
putdcc 12 [lindex $list $i]
}
-->
62.109.138.134
62.109.138.134
set ::eurostatuschaos 1
62.109.138.138
set ::eurostatusloki 1
if i leave out
  • it seems to work
Last edited by De Kus on Mon Mar 14, 2005 7:47 pm, edited 1 time in total.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: problem with switch

Post by user »

The switch command can match against variables and not just literals, as shown here
Heh..that's a weird thing to say... The switch command can match against strings, not variables...variable substitution is performed BEFORE switch recieves the values, so that manual comment is a bit misleading.
Btw: you can still add whitespace between the braces to avoid having your entire switch on a single, unreadable line:

Code: Select all

switch -- $a \
	$b {
		...
	} $c {
		...
	} default {
		...
	}
You missed the "string" part of your statement...and btw: to get a little less verbose bgerrors, (and have them displayed when they occur) make a proc called bgerror that takes a single argument and displays the contents on the partyline or whatever...
eg

Code: Select all

proc bgerror a {putlog "BGERR: $a"}
Have you ever read "The Manual"?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

okay, the last one now really helped (even improoven readability again :D).
I finally got through, here the proof:
[00:54:09] #De_Kus# set europingloki
Currently: 3004
this is normaly 0 if the switch doesn't save the expr and clock feedback :).

Code: Select all

		switch $ip \
			$::euroipchaos {
				set ::eurostatuschaos 1
			} \
			$::euroiploki {
				set ::eurostatusloki 1
			}
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked