At Sat, 15 Sep 2018 11:44:36 -0500 Richard Owlett <
row...@cloud85.net> wrote:
>
> My test code is:
>
> set infile "bookmarks.html"
> set fd_in [open $infile r]
>
> set line 0
> set mylist [list "<DT><H3" "<DT><A"]
>
> ;# <DT><H3 introduces a HEADER
> ;# <DT><A introduces a URL with associated Title
>
> while { ! [eof $fd_in] && ($line <= 25) } {
> incr line
> gets $fd_in b_line
> set a_line [string trimleft $b_line]
> set x [lsearch $mylist $a_line ]
Replace this with:
set sp1 [string first " " $a_line]
set key [string range $a_line 0 [expr {$sp1 - 1}]]
set x [lsearch $mylist $key]
You are trying to match *all* of a_line in your list, when what you want are
the two command prefixes: "<DT><H3" and "<DT><A". Note the above code
*assumes* that the <H3> tag has one or more tag options (eg it is something
like <H3 class=...> or <H3 style=...>, etc.). This will fail if it is a bare
"<H3>".
If things are not as simple minded, you might do better with something like
this code:
while { ! [eof $fd_in] && ($line <= 25) } {
incr line
gets $fd_in b_line
set a_line [string trimleft $b_line]
set x -1
foreach p $mylist {
if {[regexp -nocase "^$p" $a_line] > 0} {
set x [lsearch -exact $mylist $p]
break;
}
}
puts "$x [string range $a_line 0 20]"
}
> puts "$x [string range $a_line 0 20]"
> }
>
> close $fd_in
>
> Selected output is:
>
> -1 <!DOCTYPE NETSCAPE-Bo
> -1 <!-- This is an autom
> -1 <DT><A HREF="
http://1 <=== expected 1 <DT><A HREF="
http://1
> -1 <DT><A HREF="file:/// <=== expected 1 <DT><A HREF="file:///
> -1 <DT><H3 ADD_DATE="133 <=== expected 0 <DT><H3 ADD_DATE="133
> -1 <DL><p>
>
> Is the problem with
> set mylist [list "<DT><H3" "<DT><A"]
> or with
> set x [lsearch $mylist $a_line ]
> ?
>
> TIA
>
>
--
Robert Heller --
978-544-6933
Deepwoods Software -- Custom Software Services
http://www.deepsoft.com/ -- Linux Administration Services
hel...@deepsoft.com -- Webhosting Services