egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Remove # in front off channel.

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
T-Xorcist
Halfop


Joined: 14 Nov 2005
Posts: 47
Location: Netherlands

PostPosted: Thu Apr 13, 2006 4:54 pm    Post subject: Remove # in front off channel. Reply with quote

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.
_________________
is-1337.org IRC server!
Back to top
View user's profile Send private message Visit poster's website
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Thu Apr 13, 2006 5:31 pm    Post subject: Reply with quote

here is how to strip the # off:
Code:
regsub {#} $chan {} chan
Back to top
View user's profile Send private message
T-Xorcist
Halfop


Joined: 14 Nov 2005
Posts: 47
Location: Netherlands

PostPosted: Thu Apr 13, 2006 5:52 pm    Post subject: Reply with quote

I got this solution JUST find out:

Code:
regsub -all "#" $chan "" channelname


Bad, not safe or?
_________________
is-1337.org IRC server!
Back to top
View user's profile Send private message Visit poster's website
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Apr 13, 2006 6:58 pm    Post subject: Reply with quote

Code:
regsub {#} $chan {} chan

Would be faster. It is neater also Smile
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Fri Apr 14, 2006 7:49 am    Post subject: Reply with quote

what about a simple [string trimleft $chan #] or [string map {# ""} $chan]? No need for any always slow regex.

Code:
% 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...
Back to top
View user's profile Send private message MSN Messenger
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Apr 14, 2006 8:19 pm    Post subject: Reply with quote

.. 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
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Apr 14, 2006 8:39 pm    Post subject: Reply with quote

If you want it to still be neat but faster:
Code:
regsub {^#} $chan {} chan

This will save time since it will check only the first character if it matches '#' instead of the whole string.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Fri Apr 14, 2006 9:04 pm    Post subject: Reply with quote

Sir_Fz wrote:
If you want it to still be neat but faster:
Code:
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:
% 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
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Fri Apr 14, 2006 9:25 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Fri Apr 14, 2006 9:33 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 15, 2006 6:03 am    Post subject: Reply with quote

Well, on my pc {^#} was faster
Quote:
% 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 Razz

Interrestingly, on 100 iterations {#} is faster:
Quote:
% time {regsub {^#} #chan chan} 100
3.53 microseconds per iteration
% time {regsub {#} #chan chan} 100
3.37 microseconds per iteration

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
T-Xorcist
Halfop


Joined: 14 Nov 2005
Posts: 47
Location: Netherlands

PostPosted: Sun Apr 16, 2006 5:24 am    Post subject: Reply with quote

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

Thnx! Cool
_________________
is-1337.org IRC server!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber