HP3000-L Archives

October 1998, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Glenn Cole <[log in to unmask]>
Reply To:
Date:
Fri, 16 Oct 1998 16:02:44 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (41 lines)
Item Subject: cc:Mail Text
I love it when code just "comes together."

I need to parse a line (actually several) of comma-separated fields, like

        john,brown,ca,95014

My first thought was to use

        setvar  first_name      word( line,,1 )
        setvar  last_name       word( line,,2 )
        setvar  state           word( line,,3 )
        setvar  zip             word( line,,4 )

(These aren't the real fields; this is just an example.)

But what happens if 'city' is added later, between 'last_name' and 'state'?
I would have to renumber the indices for 'state' and 'zip'.

It turns out that the 4th and 5th parms to word() -- the resulting index
after the parse, and the starting index for the parse -- can be the same
field name!  So, while not as obvious which field is being referenced,
the following should be more maintainable:

        setvar  first_name      word( line,,1,x)
        setvar  last_name       word( line,,1,x,x )
        setvar  state           word( line,,1,x,x )
        setvar  zip             word( line,,1,x,x )

Adding 'city' requires inserting one line, and NO other modification
to the code!

This is probably "old hat" to many of you, but I just thought
it was really cool.

Great job, Jeff Vance! :)

--Glenn Cole
  Software al dente, Inc.
  [log in to unmask]

ATOM RSS1 RSS2