This started out as a SOPW entitled Hash Gravity, but somewhere around revision sixty or so, felt that maybe a Meditation would be more appropriate. Apologies in advance if mis-posted.
One of my responsibilities is maintenance of several CGI, LDAP, and GroupWise E-mail directories and mailing lists. I use Perl to manipulate the core database of account information. The data files start out as flat text files and are massaged into hash structures that are then written out using modules MLDBM and Storable::nstore for later use.
Recently I discovered that it was necessary to preserve account information for people with multiple E-mail accounts. In the past a single account was hierarchically selected as their primary account and the others ignored. Thus the system has taken on a whole new dimension (sorry, couldn't resist).
I've already got code and structures that work, but I'm curious about alternate (read more Perlish) ways to implement the structures. Note that readability is an issue since I'm the only Perl user in my office.
Below is a sub that illustrates the structures in question:
Sample results:sub DumpAccounts { my $var; my @SYS = ('GRP', 'JAG', 'CIS', 'MST', 'GCG'); my %POvars = ( 'GRP' => ['ppo', 'userid', 'email', 'gwpo', 'gwdomain'], 'JAG' => ['ppo', 'userid', 'email', 'jagexcept'], 'CIS' => ['ppo', 'userid', 'email'], 'MST' => ['ppo', 'userid', 'email'], 'GCG' => ['ppo', 'userid', 'email'] ); foreach my $ssn (sort keys %accounts) { print "$ssn "; foreach my $sys (@SYS) { if (exists $accounts{$ssn}{$sys}) { foreach $var ( @{ $POvars{$sys} }) { print $accounts{$ssn}{$sys}{$var} . " "; } print "\n" . " " x 10; } } print "\n"; } }
It seemed that using text indices ($accounts{'ssn'}{'sys'}{'vars'}) was easier for me to implement than trying to figure out the alternative $accounts{'ssn'}{sys}{var}. I'm not sure if the latter is desirable given the varying nature of the {'vars'} dimension. But even if I went with it, wouldn't the code be much more complex?123456789 JAG jblow jblow@jag.site.edu N 222222222 GRP mjones mjones@grp.site.edu ABCDE ABCDEMAIL 555555555 GRP hsimpson hsimpson@grp.site.edu FGHIJ FGHIJMAIL JAG dohhh dohhh@jag.site.edu Y GCG homers homers@gcg.site.edu
Being a multi-lingual kind of person, I tend to gravitate toward the use data structures in a way that simplifies coding and increases readability. Thus the crux of this post. What are your opinions about the balance of data structures/code complexity/readability?
Edited by footpad - 10 Aug 01, ~10:00 am (PDT)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Use ADT's to Balance everything!
by dragonchild (Archbishop) on Aug 10, 2001 at 21:26 UTC | |
by ralphie (Friar) on Aug 11, 2001 at 04:53 UTC | |
|
Re: Balancing Complexities of Data Structures, Code and Readability
by petral (Curate) on Aug 10, 2001 at 22:55 UTC | |
by tadman (Prior) on Aug 13, 2001 at 12:43 UTC | |
by John M. Dlugosz (Monsignor) on Aug 13, 2001 at 09:05 UTC | |
|
Re: Balancing Complexities of Data Structures, Code and Readability
by kjherron (Pilgrim) on Aug 10, 2001 at 22:11 UTC |