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.

need help with tcl

Old posts that have not been replied to for several years.
r
runner

need help with tcl

Post by runner »

I have a file that has multiple data for a subject and i need to get all instances of the data. But my statement only gives me one instance. etc. note1, note2 and so on.

set desc [getuser $user XTRA note]

I think I should be using lindex , but not sure how to use it.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: need help with tcl

Post by user »

runner wrote:I have a file that has multiple data for a subject and i need to get all instances of the data.
I'm not sure if I got you right, but here's my solution for what I think your problem is: Use a list to store the "instances" and 'lindex' to retrieve a single one.

Keep in mind that the XTRA field is pretty limited in length (500-length of field name), so depending on what your data is you might want to store it in a separate file.
r
runner

Post by runner »

Thanks, but I'm not sure how to use list either, its not in the tcl-commands.doc. My knowledge of tcl is very limited. I needan example.
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

runner wrote:Thanks, but I'm not sure how to use list either, its not in the tcl-commands.doc. My knowledge of tcl is very limited. I needan example.
tcl-commands.doc only has the extra commands provided by eggdrop. Here's the core tcl commands: http://tcl.tk/man/tcl8.4/TclCmd/contents.htm

Example:

Code: Select all

list "string one" "string two"
would return a list with two elements. If you stored this list some where you could later retrieve the first element by using

Code: Select all

lindex <the list> 0
...Damn, I suck at explaining. You better tell me some more about what you want to do :)
r
runner

Post by runner »

it has 1 to 50 items in note, i get the first note using set desc [getuser $user XTRA note1] but i don't get all the notes doing that. what i want to do is get all the notes. this is in my send tcl that sends me stored info on a user. the data is stored in a file that stores all users, in the file each user is listed labeled user and then under user are entries note1, note2 and so on. hope I explained this so it can be understood how the file is structured.

userfile.tx

joh doe

note1
note2
note3
Last edited by runner on Wed Aug 27, 2003 3:09 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

You mean there's note1-50 in the user's XTRA info? How about this then:

Code: Select all

foreach xtra [getuser $user XTRA] {
	if {[string match note* [lindex $xtra 0]]} {
		# insert code doing what ever you like with $xtra here
	}
}
Why are you storing things this way? Why not use the notes module?
r
runner

Post by runner »

its not really a note, i just used that for an example. its really info stored on a user.
r
runner

Post by runner »

user wrote:You mean there's note1-50 in the user's XTRA info? How about this then:

Code: Select all

foreach xtra [getuser $user XTRA] {
	if {[string match note* [lindex $xtra 0]]} {
		# insert code doing what ever you like with $xtra here
	}
}
Why are you storing things this way? Why not use the notes module?
that didn't do it, what I got from it was on users that had only one note it gave me that note, but if a user had multiple notes it gave me like only note 14.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

runner wrote:that didn't do it, what I got from it was on users that had only one note it gave me that note, but if a user had multiple notes it gave me like only note 14.
Show us some code? Did you do the output/whatever inside the loop or after it?
r
runner

Post by runner »

foreach xtra [getuser $user XTRA] {
if {[string match info* [lindex $xtra 0]]} {
set desc $xtra
}
}
I tried the code in the loop and after the loop.

both places had same result.

seems I should be able to do just
set desc [getuser $user XTRA info] this set command is already inside a foreach command.
foreach user $users {
set nikk [getuser $user XTRA nik]
set nikk [stripit $nikk]
set desc [getuser $user XTRA info]
{
Last edited by runner on Wed Aug 27, 2003 5:40 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Doing it like that will overwrite the var each time and you'll end up only keeping the last value. Use 'append' or 'lappend' to add to the variable :)
r
runner

Post by runner »

user wrote:Doing it like that will overwrite the var each time and you'll end up only keeping the last value. Use 'append' or 'lappend' to add to the variable :)
use it where, I need another example
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

what is your goal? are you going to display/write the data some where or just collect it in one big "pile" inside a variable?
r
runner

Post by runner »

no it sends me a file with the data. I just can't get it to send the user info on the file. not all of it anyway.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

If you're writing a file, just 'puts' from within the loop and everything should be fine.

eg:

Code: Select all

set file [open output.txt w]
foreach user $users {
  puts $file "$user:"
  foreach xtra [getuser $user XTRA] {
    puts $file "[lindex $xtra 0] = [lindex $xtra 1]"
  }
}
close $file
Locked