I am after some advice/comments etc on a table data system I am writing for work. I have tried using a few module available on CPAN but I was getting slow results on lookups with tables over 2/3000 records so I thought I would have a go..... I currently use 3 hashes
1) holds the basic table data %T{tableName}=[['A','B',undef,'C'],['1','2',undef,'3'],['1','2',undef, +'67']]; 2) hold the column names for each table %C{tableName}={ 'serialno' => 0, 'type' => 1, 'hardware' => 2, 'software' => 3, }); 3) holds any required indexes %I{tableName}{_checksum}{'A'}=ref_to_row ['A','B',undef,'C'] %I{tableName}{_checksum}{'1'}=ref_to_row ['1','2',undef,'3']
_checksum relates to which columns make up the index. ie col 0 is 1, col 1 is 2, col 3 is 4, col 1+3 is 5 etc.
Indexes are created dynamically during a lookup and held in the hash for use later with any similar lookups. So if we want to perform a lookup for the row with 'A' in column 1 ie lookup(tableName,{serialno=>'A'}) we simply follow the reference in the index hash.
Things i would like to improve.
1) processing every element in a table currently I do a
foreach $row (@{getTable(tableName}) # getTable() returns the ref f +rom $T{tableName}; { $row->[getColumn(tableName,'software']='updated'; # getColumn() + simply returns the result of $C{tableName}{colName} }
This works ok but I would like to find a way of NOT having to state the tableName within the loop in the call to getColumn. After all the $row is part of the table so something like
foreach $row (@{getTable(tableName}) # getTable() returns the ref f +rom $T{tableName}; { $row->column('software'); # using OO in some way ? or element($row,'software) # not so good - uses a hash of row +reference addresses to enable me to find which table any row is in }
2) mentioned OO above but I have not really used it with Perl. I'm looking into rewriting and I think it will work quite well but I'm having problems seeing how to relate tables and rows. I can bless a table into being which would contain column names and indexes. Do I make the rows sub-objects of the table ? Any ideas on how to do this so that from any given row we can find which table it is in. if all rows are objects then how do we loop through every object in a class ?
i.e foreach $row ($table)
Thanks again - any comments welcome.

In reply to table ideas/comments by wertert

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.