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.
Help for those learning Tcl or writing their own scripts.
T-Xorcist
Halfop
Posts: 47 Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:
Post
by T-Xorcist » Thu Apr 13, 2006 4:54 pm
Hi all,
I want to execute an MySQL query with the channelname in the query, like join.php?chan=$chan.
All sounds pretty neat, but MySQL / PHP does not support the # sign.
My question is, how do I remove the # in front of the channel to execute the MySQL query:
Example
-----------
Bot is in #T-Xorcist
The query will be join.php?chan=#T-Xorcist
The query MUST be join.php?chan=T-Xorcist
Can anyone help me out with this issue?
Thanks in advance.
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Thu Apr 13, 2006 5:31 pm
here is how to strip the # off:
T-Xorcist
Halfop
Posts: 47 Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:
Post
by T-Xorcist » Thu Apr 13, 2006 5:52 pm
I got this solution JUST find out:
Code: Select all
regsub -all "#" $chan "" channelname
Bad, not safe or?
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Thu Apr 13, 2006 6:58 pm
Would be faster. It is neater also
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
De Kus
Revered One
Posts: 1361 Joined: Sun Dec 15, 2002 11:41 am
Location: Germany
Post
by De Kus » Fri Apr 14, 2006 7:49 am
what about a simple [string trimleft $chan #] or [string map {# ""} $chan]? No need for any always slow regex.
Code: Select all
% time {set chan [string trimleft #channel.name #]} 100
2 microseconds per iteration
% time {set chan [string map {# ""} #channel.name]} 100
4 microseconds per iteration
% time {regsub {#} #channel.name {} chan} 100
7 microseconds per iteration
First might make troubles when using with opnotices which target is @#channel, but if you want to strip then @# anyway, you will have no trouble with it.
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...
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Fri Apr 14, 2006 8:19 pm
.. and a whole 2 microseconds is going to be a total disaster? Good grief! DragnLord's solution is not only neater but cuts code length. I prefer neat and short code.
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Fri Apr 14, 2006 8:39 pm
If you want it to still be neat but faster:
This will save time since it will check only the first character if it matches '#' instead of the whole string.
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Fri Apr 14, 2006 9:04 pm
Sir_Fz wrote: If you want it to still be neat but faster:
This will save time since it will check only the first character if it matches '#' instead of the whole string.
I would have thought so as well, until I ran the time tests.
Code: Select all
% time {regsub {#} #chan {} chan} 100
4.9 microseconds per iteration
% time {regsub {^#} #chan {} chan} 100
5.05 microseconds per iteration
Maybe those time tests aren't really that accurate.
Alchera
Revered One
Posts: 3344 Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:
Post
by Alchera » Fri Apr 14, 2006 9:25 pm
DragnLord wrote: Maybe those time tests aren't really that accurate.
They depend entirely on the efficiency of the computer they are being tested on.
Add [SOLVED] to the thread title if your issue has been.
Search |
FAQ |
RTM
DragnLord
Owner
Posts: 711 Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA
Post
by DragnLord » Fri Apr 14, 2006 9:33 pm
Alchera wrote:
They depend entirely on the efficiency of the computer they are being tested on.
And I really can't see where microseconds will matter terribly (nor can I imagine a script where the exact same command is given in a procedure a hundred times in a row).
Sir_Fz
Revered One
Posts: 3794 Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:
Post
by Sir_Fz » Sat Apr 15, 2006 6:03 am
Well, on my pc {^#} was faster
% time {regsub {^#} #chan chan} 10000
3.0633 microseconds per iteration
% time {regsub {#} #chan chan} 10000
3.2233 microseconds per iteration
% time {regsub {^#} #chan chan}
27 microseconds per iteration
% time {regsub {#} #chan chan}
28 microseconds per iteration
But, it doesn't really matter, the difference isn't that big or near to big
Interrestingly, on 100 iterations {#} is faster:
% time {regsub {^#} #chan chan} 100
3.53 microseconds per iteration
% time {regsub {#} #chan chan} 100
3.37 microseconds per iteration
T-Xorcist
Halfop
Posts: 47 Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:
Post
by T-Xorcist » Sun Apr 16, 2006 5:24 am
Thank you all for giving me so much choice of doing it LoL!
Thnx!