if {$filenum > 0} {
set filename [lindex $filelist 0]
set fileid [open $filename r]
set newfile [read $fileid]
set segments [split $newfile \r]
#Here is where I need to know how to get all of the HDR segments not
# just the first one?
[b] set HDRLoc [lsearch -regexp $segments {^HDR}][/b]
My goal is to strip out all the HDR segments except the first one.
set HDRLocList [lsearch -regexp -all $segments {^HDR}]
set HDRKeep 0
foreach HDRLoc $HDRLocList {
set HDR [lindex $segments $HDRLoc]
...
}
In case you're thinking of using lreplace to remove any (and all) HDR segments, be advised that the first lreplace operation would most likely make the list from lsearch invalid, unless you use a "lazy-delete" style of removal...
Unfortunately, 8.0 lacks many features such as the -all argument with lsearch.
I would guess the simplest approach (next to bugging your admin to upgrade tcl to 8.4ish), would be to manually step through the list (foreach) and manually test each list-item with regexp, possibly building a new list based on wether each item pass or fail the regexp-test...
I thought in the older version you could use a * instead of the -all and get the same thing, but it gives me the same error. I thought I just had the syntax wrong. Are you familar with the * matching all?
* is a wildcard used with glob-style matching, not regular expressions. It will match 0 or more characters (including whitespaces and other "special" characters).
Using *-wildcard with glob-style matching in lsearch would mean it would match each list-item against *, which would match the first item in the list, and hence return the list index for that item (obviously 0).