SirBones has asked for the wisdom of the Perl Monks concerning the following question:
Greetings all. I have a "best practices" question. What's the best way to deal with an annoying amount (from a source file maintenance point-of-view) of static text data?
I have a utility that does some data analysis on returned bit strings coming from various devices under test; one of the things it does is translate the bits that are "on" to their text meaning. For example, I might get a bit string from "device1" which looks like:
100110000000....
And so on, sometimes for several hundreds of bits. I've been keeping the meaning of the bits in various arrays:
@device1_status = qw ( Enabled Critical_fault Warning_fault Voltage_level_1_on Voltage_level_2_on . . . );
And when I walk through the bit string, it's simple enough to display the state of things:
foreach my $index (0 .. $#bits) { print "$device1_status[$index]\n" if ( $bits[$index] ); }
There are a number of possible devices, and each device has a different set of information specific to it. So sometimes I've been combining the labels into a hash of arrays:
%status = { 'dev1' => [ qw( enabled crit_fault warning_fault . . ) ], 'dev2' => [ qw( power_on OV_condition UV_condition phase_fault . . ) ], };
In any case, things have become very unwieldy in my source file. I have hundreds of lines taken up with these lists, and it will eventually number thousands. I know there must be a better way to organize this. I can think of some possibilities to separate the data and the code; I'm sure there are others:
I'm curious as to how those folks with more experience in production level Perl apps would handle this.
Thanks,
Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Best Practice for Lots of Static Data
by Firefly258 (Beadle) on Dec 01, 2006 at 02:55 UTC | |
|
Re: Best Practice for Lots of Static Data
by Util (Priest) on Dec 01, 2006 at 06:43 UTC | |
|
Re: Best Practice for Lots of Static Data
by bobf (Monsignor) on Dec 01, 2006 at 05:49 UTC | |
|
Re: Best Practice for Lots of Static Data
by wjw (Priest) on Dec 01, 2006 at 04:23 UTC | |
by cLive ;-) (Prior) on Dec 01, 2006 at 05:35 UTC | |
by Fletch (Bishop) on Dec 01, 2006 at 14:12 UTC | |
|
Re: Best Practice for Lots of Static Data
by ides (Deacon) on Dec 01, 2006 at 15:56 UTC |