tcl - Use msgread to read specific line -
i new user tcl, experience programming script 4 days.
i tried access message file. instructor introduced msg commands msgcreate, msgget, msgread.....etc.
this how file like:
nk1|1|elizabeth potter^^^^^^l|mother|ridleyton nursin nk1|1|mark davies^^^^^^l|carer|c/- cara pty.ltd.^""^woodvil8|c2||||||||||||||||||||||||||||||| pv1||i|epic^^^0014^^084^0014^^emergency patients in care|""|||i want read 3rd line detemine if index 5 o or i.
##field set field [string match *|o|* [msgget $mh]] set out "|o|" if {$field == $out} { echo patient class field: outpatient } else { echo patient class fiedl: inpatient }
i realized code read first line of file, echo me inpatient.
it appears msgget
read single line, corresponds record. fine; it's abstraction round standard tcl command gets
in likelihood. (the rest of reply assumes true.)
once you've got record, you've got split fields, can check value of. since appears |
record separator, can split things apart with:
set fields [split $record "|"]
that produces list, , can pick sec element out with:
set secondfield [lindex $field 1]; # <<< zero-base indexes, in c
combining these:
set fields [split [msgget $mh] "|"] set out "0" if {[lindex $fields 1] eq $out} { # ... }
mind you, since you're going dealing many fields, lassign
command (new in tcl 8.5, you're not on older version) works wonders:
lassign [split [msgget $mh] "|"] code inpatient name status location ...
it's sort of work works best.
(if you're dealing fixed-width fields — unlikely, maybe — should string range
or scan
.)
tcl
No comments:
Post a Comment