Please read Writeup Formatting Tips. In particular, you have asked for help on parsing a file, but I have little doubt that the act of running it though a browser has mangled it from its original form. Code and data should be wrapped in <code> tags to maintain formatting and whitespace and prevent site-specific mangling. As well, as it says in How do I post a question effectively?, "Don't post real email addresses, usernames, or passwords".

What have you tried? What didn't work? What is your experience with Perl? We appreciate shown effort around here.

Examination of your data implies you would like to transform dates from DDMONYEAR to MM\DD\YEAR format. You can do this is a fairly trivial fashion using a hash on month names and a regular expression:

#!/usr/bin/perl use strict; use warnings; my $string = '944|O|1234567890123|14NOV2010|15NOV2010|01JAN3000|C|4567 +8|COMM||045 094|O|1099721190211|14NOV2010|15NOV2010|01JAN3000|C|35077 +|FREE||044 928|O|1234567890123|14NOV2010|15NOV2010|01JAN3000|C|45678| +FREE||030 028|O|2009876543210|14NOV2010|15NOV2010|01JAN3000|C|99212|C +OMM||054'; my %months = (JAN => '01', FEB => '02', MAR => '03', APR => '04', MAY => '05', JUN => '06', JUL => '07', AUG => '08', SEP => '09', OCT => '10', NOV => '11', DEC => '12', ); $string =~ s/ (\d{2}) # Two digits ([A-Z]{3}) # Three capital letters (\d{4}) # Four digits /$months{$2}\\$1\\$3/xg; print $string;

Note this is fragile, as are most regular expressions.


In reply to Re: string manipulation by kennethk
in thread string manipulation by Anonymous Monk

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.