Since this code was intended as a teaching example, I'd change it for the following reasons:
- use meaningful variable names
- do not use single character variable names
- do not use HALT unless there is a severe error, use QUIT to go back to the calling program
- use the USE command close to the READ or WRITE that it is associated with
- do not use unnecessary intermediate arrays
- do not use multiple loops when a single one is all you need
- I just prefer to use $Principal rather than a platform-specific device number, although both work the same in all implementations that I know of
Which gives me:
Meshtree ;
kill ^mesh
set filename="mtrees2003.txt"
open filename:(readonly:exception="write "_filename_"" not found"" halt")
for use filename quit:$zeof read line do
. set key=$piece(line,";",1) ; text description
. set code=$piece(line,";",2) ; list of codes
. if (key="")!(code="") quit
. set command="Set ^mesh",separator="("
. for ii=1:1 Set part=$piece(code,".",ii) Quit:part="" Set command=command_separator_""""_part_"""",separator=","
. set command=command_")="""_key_""""
.;
.;#-----------------------------------------------------------------------
.;# command now looks like set ^mesh("A01","047")="Abdomen"
.;# now execute the text
.;#-----------------------------------------------------------------------
.;
. use $principal write command,!
. xecute command
;
close filename
use $principal write "done",!
quit
(And of course, the code assumes that neither the mesh-codes, nor the key values contain any occurrences of the character " (quote, sometimes called double quote)...)