in reply to Text file manupulation to create test files

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.

Replies are listed 'Best First'.
Re^2: Text file manupulation to create test files
by ajguitarmaniac (Sexton) on Jan 10, 2011 at 15:10 UTC

    Thanks Elisheva, your reply was very helpful.