Hi - I`m trying to retrieve the first line of a list of headlines from a webpage, but instead it gets the last one at the bottom of the list...?
Here`s the first part of the script - 2007- is what I`m using to identify the lines...
set query "http://a-website-goes-here.com"
set token [http::geturl $query]
set all [http::data $token]
foreach line [split $all \n] {
if {[string match "*2007-*" $line]} {
It gets the last line because of the foreach, each time it matches, it clobbers the 1st match.. So, you should take out the foreach, or alternatively use lappend to append each subsequent match and then use lindex 0 to get the 1st match.
set match ""
foreach line [split $all \n] {
if {[string match *2007-* $line]} {
set match "$line"
break
}
}
if {$match == ""} { return }
# continue with script