|Perl: the Markov chain saw|
Topics in Perl Programming: Table-Mutation Tolerant Database Fetches with DBIby princepawn (Parson)
|on Nov 28, 2000 at 23:38 UTC||Need Help??|
princepawn has asked for the
wisdom of the Perl Monks concerning the following question:
In terms of returned datatype, DBI supports three ways of returning data:
For the purposes of this discussion, it is a pragmatic simplification to say that you can either get an array ref or hash ref back for each row of a table.
When database fields are removed or switched in position, I call these destructive or positional field mutations. It is clear that Perl code based on array ref fetches will break in the face of such table mutations. On the other hand, hash ref fetches will not fail in this case.
When database field names are changed, I call this a labeling mutation. In this case, array ref fetches are robust to the mutation while hash ref fetches will break.
So, the dilemma which pops up when deciding on how to structure one's objects (as hashrefs or array refs) again rears its ugly head when fetching data.
And so the topic of discussion is: How does one write Perl code such that it can work without modification in the face of labeling, destructive, or positional field mutations?