Returning values from a parsed file (design issue)

D

doolittle

Hi,

I am working on a file parser, and a program that deals with the
ouptput of the parser (i'll call that the user).

I am using Perl, although I think the issues are general.

Now the user wants to get the value of a particular thing in the file.

Currently, this value could be scalar (a string), an array, or
undefined (if the thing was not in the file). Call them type3.

Some things have to be a scalar value, or undefined (or else the parser
reports the file is incorrect). Call them type2.

(other things have to be a scalar value, although i only just realised
that, call them type1. They can be caught by the parser if undef)

(Which type a thing must be is known before the file is parsed.)

I am thinking, why not (in the parser), put everything (not type1 -
well maybe) into an array, so the user just has to deal with two
possibilities (array or undefined). ie force everything of type2 or
type3 into a new type - type2A, which is either an array or undefined.

Is this a good idea?

The other possibility is just force everything of type3 into a new
type, type3A, which is which is either an array or undefined.

Should i try to make things easier for the user, or is it up to them to
deal with the basic types correctly?

dan
 
D

doolittle

I decided to put everything in list form, so the general rule to get
some data is:

my $foo = ($object->property) ? $object->property : 'null value';
for (split ( ',', $foo ) ) {processfoo ( dosomething )}

dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top