So here's the story, folks:

I'm mucking around with some config files that I know were tied with the standard AnyDBM_File (I wrote the code for portability). As you know, AnyDBM_File will choose a DBM module to use for the programmer (default NBDM, next is DB_File, etc.). To add to the confusion, some nitwit actually changed my code and used yet another dbfile format for "optimization". (yes, I really dug myself a grave by using AnyDBM_File in the first place...) Now it's my turn. Let's imagine that I have alot of these config files but they are coming from different machines and even different versions of Perl. All I want to do is to be able to open and manipulate them all reliably without too much confusion. But my dilemma comes around when one realizes that these config files are not using the same types of hash files!

So while AnyDBM_File makes it easy to create a dbfile without knowing it's type, it won't work backwards and tell me which type the file I wish to open is!

So, of course, the armed monk hits CPAN and comes up with File::MMagic, which seems like a direct match until he realizes that he would need to create his own external magic table (no support for common AND uncommon mixes of file types- discussed later)!

Being as lazy as he is, the resourceful monk tries opening any-old db with a certain dbfile module, hoping that success means that its the right format and failure otherwise. EEEEEF! Wrong again! Some modules are excellent at this while some (lowly) modules are happy to assign random binary filler data to a hash key. (Note: some such modules were written by some unnamed third parties and may not actually be available at CPAN. They also manage to completely ignore any header information, going straight for the data....)

So, the monk completely, exhausted, resorts to his wonderful friends at perlmonks.org and asks, "How can I detect a DBM file type where the above methods have failed and without a massive if-elsif block?"

Please keep in mind that File::MMagic would fail on alot of cases or that the ensuing table would become overly complicated and bloated....

Thanks in advance if you have any tips- even if they deal with File::MMagic or the UNIX file which didn't work too well either.

AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.

In reply to Not a DBengine Question. by AgentM

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.