RosettaCodeData/Task/Search-a-list/Tcl/search-a-list-2.tcl
Ingy döt Net 86c034bb8b new files
2013-04-10 12:38:42 -07:00

9 lines
369 B
Tcl

set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
foreach needle {Bush Washington} {
set indices [lsearch -all -exact $haystack $needle]
if {[llength $indices] == 0} {
error "$needle does not appear in the haystack"
} else {
puts "$needle appears first at index [lindex $indices 0] and last at [lindex $indices end]"
}
}