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 

[SOLVED] need help match something from list1 to list2

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


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Mar 09, 2013 11:13 am    Post subject: [SOLVED] need help match something from list1 to list2 Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
dirty
Halfop


Joined: 08 Feb 2013
Posts: 40
Location: Romania

PostPosted: Sat Mar 09, 2013 11:22 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Mar 09, 2013 11:38 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Mar 09, 2013 11:44 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
speechles
Revered One


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

PostPosted: Sat Mar 09, 2013 8:02 pm    Post subject: Reply with quote

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