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.
Help for those learning Tcl or writing their own scripts.
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Sat Mar 09, 2013 11:13 am
I need a code to match a number from a list with a number from another list i made so far this
Code: Select all
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)
Last edited by
Madalin on Sat Mar 09, 2013 11:44 am, edited 1 time in total.
dirty
Halfop
Posts: 40 Joined: Fri Feb 08, 2013 2:33 pm
Location: Romania
Contact:
Post
by dirty » Sat Mar 09, 2013 11:22 am
are you looking for something like this?
Code: Select all
set found ""
foreach item "a b c d" {
if {[lsearch -exact "e f a g b" $item] != "-1"} {
lappend found $item
}
}
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Sat Mar 09, 2013 11:38 am
Thats not working i will post some putlog's
<(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
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Sat Mar 09, 2013 11:44 am
Ok figured it out. I will post the solved problem here and if there is another way.. please post
Code: Select all
foreach a [array names nlu] {
foreach b $nlu($a) {
if {[llength $b]} {
do $b
}
}
}
and now
Code: Select all
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"
}
}
}
speechles
Revered One
Posts: 1398 Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)
Post
by speechles » Sat Mar 09, 2013 8:02 pm
Code: Select all
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]
}
}
}