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 

special char

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


Joined: 06 Nov 2006
Posts: 255

PostPosted: Sun Feb 08, 2009 7:29 pm    Post subject: special char Reply with quote

hello.. i have one problem.. i have one tcl script with mysql etc.. when i add one nick in one table and nick have [ ] the problem is when i export the table on php i saw the nick with { } like..

nick[1] and i see it {nick[1]} can i escape the [] and { } from any nick?

i saw here something
http://forum.egghelp.org/viewtopic.php?t=16413&highlight=escape+characters with that command

regsub -all -- {(\\|\[|\]|\&|\{|\}|"|'|\262|\263)} $data {\\\1} data

but i dont know where i must put.. on proc who read the nick or on the tcl anywhere?

thanks a lot..
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Sun Feb 08, 2009 8:38 pm    Post subject: Reply with quote

The presence of {} surrounding strings containing [] usually indicates you're actually dealing with a list.

Think you could post the code in question, would help us see if you really need that regsub, and where to put it should you do...
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
tsukeh
Voice


Joined: 20 Jan 2005
Posts: 31

PostPosted: Mon Feb 09, 2009 11:09 am    Post subject: Reply with quote

http://www.peterre.info/characters.html
Back to top
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Mon Feb 09, 2009 6:11 pm    Post subject: Reply with quote

i cant unterestand the


proc filt {data} {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}

how it works? $data what var is? i must put there my $nick1 (=nick[1]) ?

thx
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: Mon Feb 09, 2009 7:17 pm    Post subject: Reply with quote

ultralord wrote:
i cant unterestand the


proc filt {data} {
regsub -all -- \\\\ $data \\\\\\\\ data
regsub -all -- \\\[ $data \\\\\[ data
regsub -all -- \\\] $data \\\\\] data
regsub -all -- \\\} $data \\\\\} data
regsub -all -- \\\{ $data \\\\\{ data
regsub -all -- \\\" $data \\\\\" data
return $data
}

how it works? $data what var is? i must put there my $nick1 (=nick[1]) ?

thx

That filter is for avoiding double evaluation. That means before you attempt to "inject" commands into the string you run that filter over the string first. This helps protect any tcl special characters already present in the string which might get interpreted as commands. This is useful when you want to use the commands [eval] [subst] or any similar command where double-evaluation can occur. This is the reason you see so many escapes because the string is evaluated the first time, when it is turned into a string
Lets say you use this command:
set text "\[hello\]"
When the string is first evaluated we use single escapes to keep the interpreter from trying to evaluate hello as a command before it can even store anything into $text. When stored as a string these single escapes will be stripped, $text will become simply "[hello]".

But when using [subst] or [eval] over this we have a problem. The hello will be interpreted as a command because it is now being double evaluated. So the above filter can be used to keep the escapes intact when the string is stored into $text. In this way the subsequent [subst]/[eval] will not see hello as a command, but will see the escapes. And once the [subst]/[eval] evaluates the string a second time, those double evaluated escapes will also be stripped. Returning exactly the summary of the embedded commands without stumbling over any other text within.

The interpreter will evaluate three escapes \\\ back into a single escape \. The remaining will remain through each evaluation iteration, and is why you see an odd amount on the right side of the regsub, 5 of them. On the first evaluation the first three will become one. This leaves two left and combined with the one created from the first three, this again becomes three. Eggdrop likes threes. Wink

set text [filt $text]
This is how one would make use of it, but keep in mind if you aren't doing this to avoid double evaluation but instead are using it to correct bad string/list manipulations, this can make your situation even worse.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
ultralord
Master


Joined: 06 Nov 2006
Posts: 255

PostPosted: Mon Feb 09, 2009 7:38 pm    Post subject: Reply with quote

thnx i find my solution set nick1 [ join $nick1 ]

ty.
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