|
|
| Syntactic Confectionery Delight | |
| PerlMonks |
Problem With Perl IRC Serverby Veachian64 (Scribe) |
| on Jan 26, 2002 at 16:18 UTC ( [id://141797]=perlquestion: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.Veachian64 has asked for the wisdom of the Perl Monks concerning the following question:
I'm working on an IRC server written in Perl (not for any serious use, but just as a pet project of mine) and I'm running into a little trouble. I store nicknames as keys in a hash named %fhs. The value of each of those entries is the filehandle for the nickname in question, so when I need to send Bob89 data, I can just grab his filehandle from $fhs{Bob89}. The problem is, if a user wants to send information to Bob89, but sends it to bOb89, $fhs{bOb89} is checked for the filehandle and returns nothing. In order to get around this, I've had to do a case insensitive search and traverse the entire hash until I get a match with this code: That way I can use the returned nickname in the correct case and everything works just fine. The problem is, this doesn't seem very efficient and I was wondering if there was a quicker way to do it. Also, with this code, I run into problems with nicknames that contain characters used as regex metacharacters and quantifiers. For example, when Bob89^ is an online nick, nick_ison('Bob89^') prints Bob89^ as both the value of $nick and $nick_check, but the regex doesn't match it and I haven't been able to figure out a way to escape all the characters and have it still work. I tried escaping all the characters by just taking them and putting \ in front of them, but it started getting complicated when someone changed their nick to Bob89\^ and it erroneously matched Bob89^. So basically, is there a quicker way to do this and if not, what would be the best way of taking the nickname and escaping all the regex characters before using it to check for the filehandle? I'm really looking for a quicker way to write this subroutine, but if you have a way to improve the code I have, it'd be much appreciated.
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||||||