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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to retrieve list element greater than list length returns null.

Status
Not open for further replies.

luckyRaj

Technical User
Jul 13, 2005
1
US
This is a Bug while trying to retrieve element with index greater than list size.

For Eg :
set list { a b c }

llength $list = 3

lindex $list 0 = a
lindex $list 1 = b
lindex $list 2 = c

Bug : lindex $list 4 = null

WorkAround :
lindexWarn { l idx } {
if { $idx > [ llength $l ]}{
error "$idx is greater than list size"
} else { return [ lindex $l $idx ] }
}




 
change { $idx > [ llength $l ]}

to { $idx >= [ llength $l ]}

and should be OK :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top