when I chaged the data in testA file, I got this error
--error message--
"09" is an invalid octal number
while exeuting
set endTimeHour [expr int($startTimeHour + $runTimeHour)]
but, when I use 10 instead of 9, it works fine.
would you please tell me what it is wrong??
Thank you
---------code---------------------
set readFile [open "testA.txt" "r"]
set writeCommonFile [open "common.txt" "w+"]
# read the first line
gets $readFile line
# loop for each line in the file
while {![eof $readFile]} {
set lineList [split $line ,]
set lineList [string map {\" ""} $lineList]
set lineLen [llength $lineList]
set lenStartTime [expr {$lineLen - 1}]
set lenRunTime [expr {$lineLen - 3}]
set houseNum [lindex $lineList 2]
#-----------startTime + runtime-------------
# Start Time
#set startTime 7:20
#set startTime [lindex $lineList $lenStartTime]
set startTime [lindex $lineList $lenStartTime]
set splitStartTime [split $startTime :]
#remove " "
set startTimeHour [lindex $splitStartTime 0]
set startTimeMin [lindex $splitStartTime 1]
# Run Time
#set runTime 150
set runTime [lindex $lineList $lenRunTime]
set runTimeMin [expr int(fmod($runTime,60))]
set runTimeHour [expr int($runTime/60)]
# EndTime = Start Time + Run Time
set endTimeHour [expr int($startTimeHour + $runTimeHour)]
set endTimeMin [expr int($startTimeMin + $runTimeMin)]
#------calculate End Time-------------
set minFormat [expr int(fmod($endTimeMin,60))]
set hourFormat [expr int($endTimeHour + 1)]
if {$hourFormat <= 24 && $endTimeMin >= 60} {
set endTime "$hourFormat:$minFormat"
}
if {$hourFormat <= 24 && $endTimeMin <= 59} {
set endTime "$endTimeHour:$endTimeMin"
}
if {$hourFormat >= 25 && $endTimeMin >= 60} {
set overHour [expr ($hourFormat - 24)]
set endTime "$overHour:$minFormat"
}
#-----------------END of EndTime=FIRST TIME + RUN TIME ------------
set selectedData "$houseNum $startTime $endTime"
lappend storeList $selectedData; #list of lists
#puts $writeCommonFile "$houseNum"
# read the next line
gets $readFile line
}
#end of while
#--new--
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 ssL $store($elem)
set storeOpen($elem) [lsort -index 1 $ssL]
#--new
set open1 "[lindex $storeOpen($elem) 0]"
set openIndex1 [lindex $open1 0];#house number
set openIndex2 [lindex $open1 1];#earliest opening time
set storeClose($elem) [lsort -index 2 -decreasing $ssL]
#--new
set close1 "[lindex $storeClose($elem) 0]"
set closeIndex1 [lindex $close1 2];#earliest closing time
puts "The result A : $openIndex1 $openIndex2 $closeIndex1"
}
--error message--
"09" is an invalid octal number
while exeuting
set endTimeHour [expr int($startTimeHour + $runTimeHour)]
but, when I use 10 instead of 9, it works fine.
would you please tell me what it is wrong??
Thank you
---------code---------------------
set readFile [open "testA.txt" "r"]
set writeCommonFile [open "common.txt" "w+"]
# read the first line
gets $readFile line
# loop for each line in the file
while {![eof $readFile]} {
set lineList [split $line ,]
set lineList [string map {\" ""} $lineList]
set lineLen [llength $lineList]
set lenStartTime [expr {$lineLen - 1}]
set lenRunTime [expr {$lineLen - 3}]
set houseNum [lindex $lineList 2]
#-----------startTime + runtime-------------
# Start Time
#set startTime 7:20
#set startTime [lindex $lineList $lenStartTime]
set startTime [lindex $lineList $lenStartTime]
set splitStartTime [split $startTime :]
#remove " "
set startTimeHour [lindex $splitStartTime 0]
set startTimeMin [lindex $splitStartTime 1]
# Run Time
#set runTime 150
set runTime [lindex $lineList $lenRunTime]
set runTimeMin [expr int(fmod($runTime,60))]
set runTimeHour [expr int($runTime/60)]
# EndTime = Start Time + Run Time
set endTimeHour [expr int($startTimeHour + $runTimeHour)]
set endTimeMin [expr int($startTimeMin + $runTimeMin)]
#------calculate End Time-------------
set minFormat [expr int(fmod($endTimeMin,60))]
set hourFormat [expr int($endTimeHour + 1)]
if {$hourFormat <= 24 && $endTimeMin >= 60} {
set endTime "$hourFormat:$minFormat"
}
if {$hourFormat <= 24 && $endTimeMin <= 59} {
set endTime "$endTimeHour:$endTimeMin"
}
if {$hourFormat >= 25 && $endTimeMin >= 60} {
set overHour [expr ($hourFormat - 24)]
set endTime "$overHour:$minFormat"
}
#-----------------END of EndTime=FIRST TIME + RUN TIME ------------
set selectedData "$houseNum $startTime $endTime"
lappend storeList $selectedData; #list of lists
#puts $writeCommonFile "$houseNum"
# read the next line
gets $readFile line
}
#end of while
#--new--
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 ssL $store($elem)
set storeOpen($elem) [lsort -index 1 $ssL]
#--new
set open1 "[lindex $storeOpen($elem) 0]"
set openIndex1 [lindex $open1 0];#house number
set openIndex2 [lindex $open1 1];#earliest opening time
set storeClose($elem) [lsort -index 2 -decreasing $ssL]
#--new
set close1 "[lindex $storeClose($elem) 0]"
set closeIndex1 [lindex $close1 2];#earliest closing time
puts "The result A : $openIndex1 $openIndex2 $closeIndex1"
}