| View previous topic :: View next topic |
| Author |
Message |
rubenmb Voice
Joined: 15 Apr 2006 Posts: 3
|
Posted: Sat Jan 20, 2007 3:25 pm Post subject: One result in public, the rest in private |
|
|
Hi everyone,
Here's what i want to do. I have some results from a mysql query, lets say like 10. And right now, i am using a foreach loop to set my variables for each one of the results and output them into one channel. Now what i want to do is output the first result it finds in public, and all the rest in private.
Anyone has an idea on how this could be done? |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Sat Jan 20, 2007 6:27 pm Post subject: Re: One result in public, the rest in private |
|
|
| Code: | puthelp "PRIVMSG #chan :[lindex $list 0]"
foreach item [lrange $list 1 end] {
puthelp "PRIVMSG nick :$item"
} |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
rubenmb Voice
Joined: 15 Apr 2006 Posts: 3
|
Posted: Sat Jan 20, 2007 9:35 pm Post subject: |
|
|
That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:
| Code: | {some text more text}
|
lindex will result in an output of those words like they were diferent results:
| Code: | some
text
more
text
|
 |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Sat Jan 20, 2007 9:53 pm Post subject: |
|
|
In your first post you said you used foreach to create some variables... $list in my example would be the list you passed to foreach. _________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Jan 20, 2007 10:20 pm Post subject: |
|
|
| rubenmb wrote: | That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:
| Code: | {some text more text}
|
lindex will result in an output of those words like they were diferent results:
| Code: | some
text
more
text
|
 |
Yeah, and for
| Code: | | {"some text" "more text"} |
lindex will result in
| Quote: | some text
more text |
_________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
rubenmb Voice
Joined: 15 Apr 2006 Posts: 3
|
Posted: Sat Jan 20, 2007 11:12 pm Post subject: |
|
|
Yes user your right, i should have posted you some code.
And that way you would see that after calling the foreach i handle each argument of each string in a way
that makes it impossible to use the method you posted,
because its no longer:
| Code: | | {some text and more text} {second result text} {and so on} |
after my foreach it'll be something like:
| Code: | | [TAG] Result 1: \002some text and more text\002 |
for each of the resulted data.
But your help was still very much appreciated, cause basing my self on that
i was able to tweak the script and end up with what i wanted.
I'll explain for the ones that will run into the same problem:
| Code: |
## instead of looping around the raw data first
## I separated the first result ($n1) from the rest ($nx)
set n1 [lindex $data 0]
set nx [lrange $data 1 end]
## then i submited the first result to my proc with type=public
my_proc $n1 $needed $variables public
## for the rest of the results, and now yes, i use a foreach loop and type=private
foreach item $nx {
my_proc $item $needed $variables private
}
## then on my proc
proc my_proc { item needed variables type }
set this
set that
bla bla
if {$type == "public"} {
putserv "PRIVMSG $channel :$line"
} else {
putserv "PRIVMSG $nick :$line"}
}
|
So thats how i pull it off
Again thanks for the help user
regards |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Sat Jan 20, 2007 11:51 pm Post subject: |
|
|
So basically, you did exactly what user suggested  _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
|