Fellow Monks,

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:

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"; } }
Sample results:
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
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?

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)


In reply to Balancing Complexities of Data Structures, Code and Readability by jlongino

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.