All:
Warning! This is going to be a long post.

I recently read this post by Elian and two of things hit me like a ton of bricks:

  • If you're going to use it in more than two programs, make it a module
  • If doing it even once made your head hurt, throw it in a module

    I have to work with really nasty data. A typical record looks like the following:

    key : /C=US/A=BOGUS/P=ABC+DEF/O=CONN/OU=VALUE1/S=Region/G= +Limbi c/I=_/ type : UR flags : DIRM ADMINM ADIC ADIM Alias-2 : wL_Region Alias-3 : Limbic Region Alias-4 : Limbic._.Region@nowhere.com Alias-5 : Limbic._.Region Alias-6 : Limbic.Region@nowhere.com Alias-7 : ORG Alias-8 : CMP Alias-10 : O=ORG/OU=Some Big Division/CN=Limbic _. Region Alias-11 : Region Alias-12 : Region, Limbic _ Alias-14 : Limbic _. Region at WT-CONN Alias-15 : ex:/o=BLANK/ou=ORG/cn=Recipients/cn=Mailboxes/cn=LRe +gion Alias-16 : WT:Limbic_Region Alias-17 : SMTP:Limbic._.Region@nowhere.com Alias-18 : /o=A.B.C.D./ou=Vermont Ave/cn=Recipients/cn=wt/cn=Li +mbic_Regi on Full Name : Region, Limbic _. Post Office : WT-CONN Description : 999-555-1212 Some Big Company Tel : 999-555-1212 Dept : Some Big Division Location : EMWS Address : 123 nowhere street City : everywhere State : MD Zip Code : 20874 Building : BLAH Building-Code : MD-ABC owner : CONN

    I am typically batch processing records, and not obtaining a single record. The problem is, that the only tools we currently have for this is shell scripts with a lot of VERY ugly sed. Even then, there are a great deal of limitations. I have written a few custom scripts in Perl, but they really aren't re-useable as each task is different.
    This seems like a perfect place to use a module.

    Here are some issues I can see up front:

  • Some entries can be on multiple lines, but if it is continued - it will always be indented by a tab
  • Some entries are guaranteed to be unique. Only the key is guaranteed to be present and unique
  • The key is / delimited, but there may be an imbedded \/ that is escaped that is not a delimeter
  • I will need the key both in concatenated format and broken down into each piece
  • Should I make this OO
  • These are the main things I will need to do:

  • Skip the record because it doesn't not match criteria
  • Manipulate the record based off criteria
  • Print the record

    Here is what I envision:

    #!/usr/bin/perl -w use strict; use DBParser; # My new module I haven't built yet open (OUTPUT,"> /tmp/somefile") or die $!; select OUTPUT; $|++; $/=""; while (<>) { my $key = DBParser::KeyGrab($_); my %record = DBParser::DBParse($_); next unless ($record{$key}->{Key}->{Surname} eq "Region"); $record{key}->{Tel} = "(123) 456-7890"; print DBParser::PrintRecord; }

    I certainly don't want anyone to write this module for me - the whole point in the project is to learn. I do however want pointers, advice, snippets of code, etc. Feel free to reply as though this was a meditation, if all you have to offer is methodologies and not actual technical solutions.

    Thanks in advance - L~R


    In reply to My first package - need help getting started by Limbic~Region

    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.