A co-worker supports a POS system. At month end, system A creates some new XML, and sends them to System B that processes them into a billing system.

Problem is that System B only handles a 10 character OPERATORID value, and System A will create 12 character OPERATORID's. So hundred's of these are rejected. cute, eh?

So we get System A to only send 10 chars, right? wrong.

For whatever reason, this co-worker decided to HAND MASSAGE the files and using notepad to truncate all the rogue >10 chars strings.

Last month the system spit out over 400 of these rejections (business is picking up!).

while watching this co-worker hand-massage these files, I decided to write up a quick script to do it for him.

It's not going to win any prizes in a perl contest, but it sure solved a huge problem for my co-worker.

The file works against one file at a time (it started as an attempt at a one-liner, but time was of the essence and I was not clever enough to do it that way). I wrote a second perl script to build a big .BAT file from the directory listing the files resided in. The batch file executes this script against each file.

I thought I would just share the story, but I will be brave and include the code, such as it is.

#!perl.exe # invoke as follows: # perl -p -i.BAK posfix.pl FILENAMETOPROCESS # if ( /OPERATORID/ ) { $_ =~ s/<OPERATORID>//; $_=~ s/<\/OPERATORID>//; $_=substr($_,0,10); $_ = "<OPERATORID>". $_ . "</OPERATORID>\n"; }


In reply to Quick solutions to easy problems by wardk

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.