If I'm reading what you wrote above correctly you want to split the first line of each subscriber loop into four or more lines, let's say 1a, 1b, 1c, 1d. These will be followed by the remaining lines of the subscriber loop.

To do this task, you are going to need to review working with hashes if you haven't done so already. The algorithm would look something like this:

  1. Read line 1 of subscriber loop - convert into hash with hash entries being the property-value pairs found on the first subscriber line. Thus line 1 would look like this at the end of this step.
    $hLine = { SBSB_ID => '123456782' , First_name => "Ryan" , Last_name => "George" , WMDS_SEQ_NO1 => 2 , WMDS_SEQ_NO22 => 3 #, .... and so on for each field ... };
  2. Next print line 1a, extracting and printing property names and values you want (SBSB_ID, First_name, Last_name) from the hash.
  3. Delete the hash keys that you've printed. What you'll have left is the properties that you want to have one per line.
  4. For each remaining key-value pair in the hash, print one per line. That completes the processing of line 1 of the subscriber loop.
  5. For the remaining lines of the subscriber loop, read in each line and print as is
  6. When you detect the end of the subscriber loop, return to step 1, unless you are at the end of the file.

Of course, there are many ways to do this, depending on what you know about the properties that belong on lines 1b, 1c, 1d, etc. For example, in step 3, if you know that the one-property-per-line properties always have the format WMDS_SEQ_NO# where # is some number, then you can skip the "delete each key" part above and just do a map with a regex, something like this (not checked for typos):

foreach my $k (grep { /^WMDS_SEQ_NO\d+$/ } sort keys %$hLine) { print $fh "$k=".$hLine->{$k}."\n" }

Update: I just noticed the requirement to replicate each subscriber loop. This requires a some changes to the above algorithm.

Update: fixed instruction numbering error.


In reply to Re: Text file manupulation to create test files by ELISHEVA
in thread Text file manupulation to create test files by ajguitarmaniac

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.