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.

spliting chars ..

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

spliting chars ..

Post by Ofloo »

is there a way beter way to do this and make it work tho cause this aint working

Code: Select all

set modesArray(nick_#chan_#) abc
set modesArray(nick_#chan) def
set modesArray(nick_#_##_#) ghi

foreach {a b} "[lindex [string map {\x5F\x23 \x20\x23} [array names modesArray]] 0] [string map {\x20\x23 \x5F\x23} [join [lrange [string map {\x5F\x23 \x20\x23} [array names modesArray]] 1 end]]]" { 
puts "NICK: $a CHAN: $b" 
}
normal i would do

you can also do this with regexp but i can't find he proper synatx to do so ..
i also tryed with regexp but i am not able to get the proper syntax ..

split [array names modesArray] \x5F

but because channel names & nick names can contain a "_" char \x5F .. i have to find an other way..
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

you could probably do this with regexp as well and i tryed but can't find the proper syntax

* couldn't edit ...
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

wtf are you trying to do and why don't you use a char that can't be part of a nick/channel name? like ","?
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

well i was trying to think of one lol sorry hehe
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

allready found a way ;)

Code: Select all

foreach x [array names modesArray] {
  puts "NICK [lindex [string map {\x5F\x23 \x20\x23} $x] 0] CHAN [strin map {\x20\x23 \x5F\x23} [join [lrange [string map {\x5F\x23 \x20\x23} $x] 1 end]]]]"
}
XplaiN but think of me as stupid
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Ofloo wrote:allready found a way ;)

Code: Select all

foreach x [array names modesArray] {
  puts "NICK [lindex [string map {\x5F\x23 \x20\x23} $x] 0] CHAN [strin map {\x20\x23 \x5F\x23} [join [lrange [string map {\x5F\x23 \x20\x23} $x] 1 end]]]]"
}
Looks like you're using lindex/lrange on a string there... and btw: there's nothing wrong with writing those chars directly in your code instead of using escapes. The escapes just add to the number of substitutions required and slow things down.
Here's a regexp to do the "splitting" for you (if you refuse to change the join to a single char :P)

Code: Select all

regexp {^(.+?)_(#.*)$} $x nick nick chan
And here's why you should consider using a single char:

Code: Select all

# some test data
array set a {nick,#chan abc nick,#chan2 def nick,#chan3 ghi nick,#chan4 jkl nick,#chan5 mno}
# some tests
foreach way {
	{foreach {n c} [split [join [array names a] ,] ,] {set xxx $n,$c}}
	{foreach n [array names a] {scan $n {%[^,],%s} n c; set xxx $n,$c}}
	{foreach n [array names a] {set i [expr {[string first ",#" $n]-1}]; set xxx [string range $n 0 $i],[string range $n [incr i 2] end]}}
	{foreach n [array names a] {regexp {^(.+?),(.+)$} $n n n c; set xxx $n,$c}}
	{foreach n [array names a] {set xxx [lindex [split [string map {, " "} $n]] 0],[join [lrange [split [string map {, " "} $n]] 1 end] ""]}}
} {
	puts "[time $way 10000]: $way"
}
Run it and take a look at the times :)
The first one is similar to your first suggestion
The last one is roughly what you did in your final solution
The third way would also handle multiple chars (if you insist on that) and seems to be about twice as fast as your map/split/join/lrange+join thing :)
Have you ever read "The Manual"?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

verry nice indeed.. i knew it was gone slow it a bit down but didn't expected so mutch.. tnx .
XplaiN but think of me as stupid
Locked