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.
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.
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.
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.
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?
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 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