Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Thoughts on designing a file format.

by leriksen (Curate)
on Sep 13, 2005 at 23:43 UTC ( #491724=note: print w/ replies, xml ) Need Help??


in reply to Thoughts on designing a file format.

Something I have found useful for flat files, not hierarchical files, is to have the names of the columns as the first line.

This helps avoid hardcoding the column names in your parsing/construction code - I'd expect the names will embedded in the code that utilises the constructed structure, after all, its hard to escape the need to type "$row->{address}" when you need to access the address field (or $row->address() if you've built objects to give yourself one degreee of separation)

With the columns names as the first row, you are insulated from the introduction of new columns until you really need them. For example, say you have columns 'name','street','town','country'. You have code to parse this line and create the appropriate accessors, and more code that reads a line and, for each line, returns an object that has these accessor methods. You then have code that uses these objects to build address labels or populate a database. Then one day the client who suplies these files adds a new field, say zip code, and it is in the data between the town and country columns. NONE of your code has to change until your ready to use the zip code field. Your objects have an extra accessor, which is automatically created by the code that parses the column-description line, but nothing else is affected.

It could be you want to add the zip code to the address labels, but you dont want to change the DB schema to capture zip codes. You change the label generation code, and leave the DB insert code alone. So your DB inserts continue to work, and your address labels now have zip codes.

All because you were able to have the client give you one extra line in the supplied flat files.

...reality must take precedence over public relations, for nature cannot be fooled. - R P Feynmann


Comment on Re: Thoughts on designing a file format.
Re^2: Thoughts on designing a file format.
by demerphq (Chancellor) on Sep 14, 2005 at 06:57 UTC

    Field header rows can be useful indeed. However they are only really applicable to files that contain only a single record type. Many of the files i deal with contain multiple record types. But its a good point, thanks.

    ---
    $world=~s/war/peace/g

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://491724]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-12-18 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls