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.

i really need ur help... tcl list

Help for those learning Tcl or writing their own scripts.
Post Reply
m
myWorldTCL
Voice
Posts: 5
Joined: Thu Jul 31, 2008 4:55 am

i really need ur help... tcl list

Post by myWorldTCL »

i run this code in dmh console...

Code: Select all

while {[string match \{*\} $mbxmsg] && [llength $mbxmsg]==1} {
		set list [lindex $mbxmsg 0]
		
	}
		return [list $mbxmsg]
		
		set a [lindex $mbxmsg 0]
		set b [llength $mbxmsg]
		while {$a < $b} {	
			set x [linsert $a $b]
			puts "[localtime 9], $x"
			incr b 
			mbx whenmsg again 
	}

then insert the list {{1 2 3} {4 5 6}}.. there has no output display.. whats the problem???
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

There's no need to double-post.
'return' returns (the lines below are never executed) ...also, your code doesn't make much sense to me. It would be easier to help you if you explain exactly what you are trying to do.
Have you ever read "The Manual"?
m
myWorldTCL
Voice
Posts: 5
Joined: Thu Jul 31, 2008 4:55 am

i want to display both of list

Post by myWorldTCL »

regarding to my question, i want to display both of list: {{1 2 3} {4 5 6}}
the coding is same as above... i have post before this.. then i execute the source file... and execute both of list {{1 2 3} {4 5 6}}, but there has no result display for both of list....


my question is, how to display more than one list??? let say if i execute three list like this: {{1 2 3} {4 5 6} {7 8 9}}?? maybe you can help me to correct my coding... im new of using this tcl..
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: i want to display both of list

Post by user »

Sorry for the delay... we had a power failure at work.

Code: Select all

foreach sublist $listOfLists {
	# do something to $sublist
}
...and you probably want to replace 'puts' with 'putlog' if you're running this script in an eggdrop. :wink:
Have you ever read "The Manual"?
m
myWorldTCL
Voice
Posts: 5
Joined: Thu Jul 31, 2008 4:55 am

i still not get it

Post by myWorldTCL »

can u show me the real thing?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I find it very hard to figure out what the "real thing" would be. The code you posted is not only confusing, but riddled with bugs. All I've gathered is that you are trying to use "DMH Mailbox messaging"?

First off, you have a while-loop that will run as long as $a (the first list item of the recieved message) is smaller than $b, which is increased for each iteration of the loop. Hence you have a possible infinite loop.

Next, you use linsert with $a as list, and $b as index, yet you fail to supply an entity to add, causing a fatal error.

Finally, assuming those two items were fixed, you'd still end up writing the same line over and over, or possibly with added content for each iteration of the loop.


If you are working with a tcl-shell (tclsh or similar), use something like this to simply print the contents of the list:

Code: Select all

foreach sublist $mbxmsg {
  puts $sublist
}
(With eggdrop, you'd simply replace puts with putlog to send the output to the log, or puthelp to build a command to send to the irc-server...)
NML_375
m
myWorldTCL
Voice
Posts: 5
Joined: Thu Jul 31, 2008 4:55 am

i still not get it

Post by myWorldTCL »

yes im using DMH Mailbox messaging... so what shud i do to perform the code that u gave it to me juz now?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, you'll have to explain what you wish to achieve...
Do you simply wish to dump the lists to stdout? If so, the code posted will do just that.
If you wish to do something more, explain it, because I have no clue what further processing you'd like to do...
NML_375
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

while {[string match \{*\} $mbxmsg] && [llength $mbxmsg]==1} {
set list [lindex $mbxmsg 0]

}
return [list $mbxmsg] 
It appears this part uses a while (why not an if?) to check to see if there are curly braces in the string, then checks the llength against a string?! which basically returns the 1 so of course =='s it. Then it sets the lindex to 0 to remove the curly bracings? Did it assume it was a list incorrectly? But wait, lower down it returns a list of one element consisting of the contents of $mbxmsg. This is an obvious horribly written kludge to turn a string into a list.

Code: Select all

set a [lindex $mbxmsg 0]
set b [llength $mbxmsg] 
Then lower down we have this code which treats it as list? then the rest of it makes no sense to me. And really none of the above does either, I can just tell why it was written. As nml375 said, to get more help you have to show more code. What is posted goes all over the place and leaves too much out.
Post Reply