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!

invalid octal number

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
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"

}

 
this is testA.txt
1 "08:10" "12:00" <--error occured "08:10"
1 "09: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
 
oh I got it...I used scan
scan $startTimeHour %d startTimeHour
right??
 
Basically, yes. Tcl reads everything as a string. A string that starts with a "0" followed by a number is presumed to be an octal number (so 07 will work but not 08) unless the processor is explicitly directed to treat it differently.

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top