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.

Remove # in front off channel.

Help for those learning Tcl or writing their own scripts.
Post Reply
T
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Remove # in front off channel.

Post by T-Xorcist »

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.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

here is how to strip the # off:

Code: Select all

regsub {#} $chan {} chan
T
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Post by T-Xorcist »

I got this solution JUST find out:

Code: Select all

regsub -all "#" $chan "" channelname
Bad, not safe or?
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Code: Select all

regsub {#} $chan {} chan
Would be faster. It is neater also :)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

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...
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

.. 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
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

If you want it to still be neat but faster:

Code: Select all

regsub {^#} $chan {} chan
This will save time since it will check only the first character if it matches '#' instead of the whole string.
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

Sir_Fz wrote:If you want it to still be neat but faster:

Code: Select all

regsub {^#} $chan {} chan
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. :wink:
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

DragnLord wrote:Maybe those time tests aren't really that accurate. :wink:
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
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

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).
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

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 :P

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
T-Xorcist
Halfop
Posts: 47
Joined: Mon Nov 14, 2005 6:36 pm
Location: Netherlands
Contact:

Post by T-Xorcist »

Thank you all for giving me so much choice of doing it LoL!

Thnx! 8)
Post Reply