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 

mysqltcl: replace string [Solved]

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


Joined: 20 May 2011
Posts: 3

PostPosted: Fri May 20, 2011 4:14 pm    Post subject: mysqltcl: replace string [Solved] Reply with quote

Hi. I have an Eggdrop connecting to a MySQL database using mysqltcl and displaying the info on an IRC channel. Some rows contain text that I don't want to display like <br> and I want to omit it.

I tried to use the "string map" function ( http://wiki.tcl.tk/2819 ) but the bot crashed when it read the <br> on string map {<br> } $post. Then I tried to put only br to see if I was using it correctly but it seemed that the instruction was ignored.

I'm using this code to experiment:

Code:

mysqlmap $db_handle {id username post date} {
  string map {br |} $post
  putserv "privmsg $chan :$post"
}


But it display the text normally. What am I doing wrong?


Last edited by Pad on Sat May 21, 2011 4:08 pm; edited 1 time in total
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri May 20, 2011 6:03 pm    Post subject: Re: mysqltcl: replace string Reply with quote

Code:
mysqlmap $db_handle {id username post date} {
  set post [string map [list "<br>" " | "] $post]
  putserv "privmsg $chan :$post"
}

You use the string map to convert, but are never storing those results as a variable. I included the "set post" and bracket encapsulation [ ] around the [string map] to properly build the correct sequence of commands (stacking). I've also used [list "replace-this" "with-this"] which will work properly regarding variables replacements and special characters (ie, un-exploitable via errors or otherwise), as [list] is the preferred way to do [string map] rather than hand-crafting within curly braces { }.

School is now in session. The bell has rang. Classroom is filling with students. Grab a seat while you can... Wink

/me takes a bite of the apple on his desk.

Having fun, is of tantamount importance as the task at hand. Remember this. Don't get angry, or give up when learning tcl. Have fun. Consider your failures as lessons, character building exercises. Not as some fundamental skill you lackl. Nobody is perfect. Having a laugh at stupid mistakes helps. Having fun while coding seriously is why I have a lot of success. For no other reason. I enjoy scripting for eggdrop. This is what keeps me sane. This is my wooden ship in a bottle, that I slowly build meticulously piece by piece over time.
_________________
speechles' eggdrop tcl archive


Last edited by speechles on Fri May 20, 2011 6:22 pm; edited 1 time in total
Back to top
View user's profile Send private message
Pad
Voice


Joined: 20 May 2011
Posts: 3

PostPosted: Fri May 20, 2011 6:21 pm    Post subject: Re: mysqltcl: replace string Reply with quote

It worked! Thank you! Very Happy

One more thing: is there any special character in IRC to make a newline like '\n' for PHP, C, etc?
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Fri May 20, 2011 6:25 pm    Post subject: Reply with quote

Code:
mysqlmap $db_handle {id username post date} {
  set post [string map [list "<br>" "\n"] $post]
  foreach line [split $post "\n"] {
    putserv "privmsg $chan :$line"
  }
}

This will show you how to encapsulate and render newlines. Try this one too.. Wink
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
Pad
Voice


Joined: 20 May 2011
Posts: 3

PostPosted: Fri May 20, 2011 6:35 pm    Post subject: Reply with quote

It worked too! Thank you very much! Very Happy
Back to top
View user's profile Send private message
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