| View previous topic :: View next topic |
| Author |
Message |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat Mar 09, 2013 11:13 am Post subject: [SOLVED] need help match something from list1 to list2 |
|
|
I need a code to match a number from a list with a number from another list i made so far this
| Code: |
foreach a [array names nlu] {
foreach b $nlu($a) {
if {[llength $b]} {
foreach c [split $data "\n"] {
incr nr
if {$b == $nr} {
putlog "$b == $nr -- matched \002$c\002 for $b"
}
}
}
}
}
|
The problem is that $nlu($a) is formed from 2 or 3 numbers for example 1 2 3 and when the foreach triggeres it only matches the first one with the second list and then it start from where it found the first number (but i need it to start from 0 or something to match the others and make a temp(list) _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Last edited by Madalin on Sat Mar 09, 2013 11:44 am; edited 1 time in total |
|
| Back to top |
|
 |
dirty Halfop
Joined: 08 Feb 2013 Posts: 40 Location: Romania
|
Posted: Sat Mar 09, 2013 11:22 am Post subject: |
|
|
are you looking for something like this?
| Code: |
set found ""
foreach item "a b c d" {
if {[lsearch -exact "e f a g b" $item] != "-1"} {
lappend found $item
}
}
|
_________________ come to the dark side.. I have cookies!
WwW.BotZone.TK |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat Mar 09, 2013 11:38 am Post subject: |
|
|
Thats not working i will post some putlog's
| Quote: |
<(EggHelp> [17:33:07] 4 == 1 ??
<(EggHelp> [17:33:07] 4 == 2 ??
<(EggHelp> [17:33:07] 4 == 3 ??
<(EggHelp> [17:33:07] 4 == 4 -- matched Balefire Caster for 4
<(EggHelp> [17:33:07] 4 == 4 ??
<(EggHelp> [17:33:07] 4 == 5 ??
<(EggHelp> [17:33:07] 4 == 6 ??
....
<(EggHelp> [17:33:07] 4 == 133 ??
<(EggHelp> [17:33:07] 5 == 134 ??
<(EggHelp> [17:33:07] 5 == 135 ??
<(EggHelp> [17:33:07] 5 == 136 ??
<(EggHelp> [17:33:07] 5 == 137 ??
<(EggHelp> [17:33:07] 5 == 138 ??
<(EggHelp> [17:33:07] 5 == 139 ??
<(EggHelp> [17:33:07] 5 == 140 ??
<(EggHelp> [17:33:07] 5 == 141 ??
...
|
So when it should get the second element from the first list it should start the list2 from 0 but it doesnt it just continues the first one _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat Mar 09, 2013 11:44 am Post subject: |
|
|
Ok figured it out. I will post the solved problem here and if there is another way.. please post
| Code: |
foreach a [array names nlu] {
foreach b $nlu($a) {
if {[llength $b]} {
do $b
}
}
}
|
and now
| Code: |
proc do {b} {
global temp fstats bid item nlu nl
set fp [open "temp" r]
set data [read $fp]
close $fp
set nr 0
foreach c [split $data "\n"] {
incr nr
if {$b == $nr} {
putlog "$b == $nr -- matched \002$c\002 for $b"
}
}
}
|
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
speechles Revered One

Joined: 26 Aug 2006 Posts: 1398 Location: emerald triangle, california (coastal redwoods)
|
Posted: Sat Mar 09, 2013 8:02 pm Post subject: |
|
|
| Code: | set fp [open "temp" r]
set data [split [read -nonewline $fp] \n]
close $fp
foreach a [array names nlu] {
foreach b $nlu($a) {
if {[string length $b]} {
set lpos 0
while {[set pos [lsearch -exact -start $lpos $data $b]]>-1} {
putlog "$b == [expr {$pos+1}] -- matched \002[lindex $data $pos]\002 for $b"
set lpos [incr pos]
}
}
} |
_________________ speechles' eggdrop tcl archive |
|
| Back to top |
|
 |
|