Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Min, Max TCL Command. 3

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
is there any way to find minimum value or maximum value??
 
Whoa, lot of activity today, huh?

I think I solved your questions regarding your two issues:
(Note: I did test this!)

1.)
if I want to have

num 1's earliest time and lasted time
num 2's earliest time and lasted time
num 3's earliest time and lasted time

2.)
what if I don't know exact numbers?
num1
num2
num3


This works great, give it a try ! I've just appended code to your previous code, beginning at Start of cptk's

set readFile [open "listsort.txt" "r"]

gets $readFile line

while {![eof $readFile]} {

# write the line to the backup file "output this line to a file"
set lineList1 [string map {\" ""} $line]
set storeNum [lindex $lineList1 0]
set startTime [lindex $lineList1 1]
set closeTime [lindex $lineList1 2]
puts "$storeNum $startTime $closeTime"

#set lineList2 [split $lineList1 " "]; #make a proper list
lappend storeList $lineList1; #list of lists

gets $readFile line
}

#now work on storeList
#set openList [lsort -index 1 $storeList]
set openList [lsort -index 1 $storeList]
puts "earliest opening time = [lindex $openList 0]"
set closeList [lsort -index 2 -decreasing $storeList]
puts "latest closing time = [lindex $closeList 0]"

##### Start of cptk's #####

set StoreName ""
set StoreId ""
set StoreNum ""

for {set i 0} {$i < [llength $storeList]} {incr i} {

if {$StoreId == [lindex [lindex $storeList $i] 0]} {
lappend store($StoreId) [lindex $storeList $i]

} else {
set StoreId [lindex [lindex $storeList $i] 0]
lappend store($StoreId) [lindex $storeList $i]
}

if {[lsearch -exact $StoreName store($StoreId)] == -1} {
lappend StoreName store($StoreId)
lappend StoreNum $StoreId
}
}

set StoreNum [lsort -index 0 $StoreNum]
foreach elem $StoreNum {

set storeOpen($elem) [lsort -index 1 $store($elem)]
set storeClose($elem) [lsort -index 2 -decreasing $store($elem)]

puts "Store # $elem Early : [lindex [lindex $storeOpen($elem) 0] 1]"
puts "Store # $elem Lastest: [lindex [lindex $storeClose($elem) 0] 2]"
}

 
I got this answer
1 10:10 16:00
2 11:10 17:00
3 11:20 18:00

here is a code.
but if you have any good idea, please advise me.
if we don't know "num", let say 1000
can I use "while" loop?

I think..I need to change this loop to for-loop
Do you have any idea??

thank you
---------------
foreach elm $storeList {
switch [lindex $elm 0] {
1 {lappend sublist1 $elm}
2 {lappend sublist2 $elm}
3 {lappend sublist3 $elm}
}
}
---------------------------
Thank you all
---b.txt---
num open close
1 "10:10" "12:00"
1 "12:10" "14:00"
1 "14:10" "16:00"
2 "11:10" "13:00"
2 "14:10" "16:00"
2 "15:10" "17:00"
3 "11:20" "12:00"
3 "12:10" "13:00"
3 "14:10" "18:00"
-------------------
set readFile [open "b.txt" "r"]

gets $readFile line

while {![eof $readFile]} {

# write the line to the backup file "output this line to a file"
set lineList1 [string map {\" ""} $line]
set storeNum [lindex $lineList1 0]
set startTime [lindex $lineList1 1]
set closeTime [lindex $lineList1 2]
puts "$storeNum $startTime $closeTime"

lappend storeList $lineList1; #list of lists

gets $readFile line
}


puts "#######"

foreach elm $storeList {
switch [lindex $elm 0] {
1 {lappend sublist1 $elm}
2 {lappend sublist2 $elm}
3 {lappend sublist3 $elm}
}
}
#--------num1
set openListA [lsort -index 1 $sublist1]
set openA "[lindex $openListA 0]"
set openAindex1 [lindex $openA 0];#house number
set openAindex2 [lindex $openA 1];#earliest opening time
set closeListA [lsort -index 2 -decreasing $sublist1]
set closeA "[lindex $closeListA 0]"
set closeAindex1 [lindex $closeA 2];#earliest opening time
puts "The result A : $openAindex1 $openAindex2 $closeAindex1"


#--------num2
set openListB [lsort -index 1 $sublist2]
set openB "[lindex $openListB 0]"
set openBindex1 [lindex $openB 0];#house number
set openBindex2 [lindex $openB 1];#earliest opening time
set closeListB [lsort -index 2 -decreasing $sublist2]
set closeB "[lindex $closeListB 0]"
set closeBindex1 [lindex $closeB 2];#earliest opening time
puts "The result B : $openBindex1 $openBindex2 $closeBindex1"

#--------num3
set openListC [lsort -index 1 $sublist3]
set openC "[lindex $openListC 0]"
set openCindex1 [lindex $openC 0];#house number
set openCindex2 [lindex $openC 1];#earliest opening time
set closeListC [lsort -index 2 -decreasing $sublist3]
set closeC "[lindex $closeListC 0]"
set closeCindex1 [lindex $closeC 2];#earliest opening time
puts "The result C : $openCindex1 $openCindex2 $closeCindex1"
 
oh..I got the result what I want..

Thank you all

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top