if there are multiple records in the file only the first is printed.
Sure, you did not describe your input data and only gave one sample. I based the suggested program on your data sample. The first sample you gave only had one "CF" line, so I made the first program based on that sample. And it worked.

Then you gave another sample with several "CF" lines (but still only one record block), so I changed my program to fit this new data sample. And it worked.

Now, you're saying that there can be several record blocks. How were we supposed to guess that? Well, in fact, I sort of guessed it would plausibly be the case, but I could not write a program based on an inexistent data sample.

So this is the third version:

use strict; use warnings; my $line; while (<DATA>) { if (/^\s*MSISDN=(\d+);/) { print "$line\n" if defined $line; $line = $1 ; } if (/\s*CF=([\w-]+?-(?:NONE|\d+))/) { my $add = $1; $add =~ s{(\d+)$}{1/1/1/$1}; $add =~ s{NONE}{1/1/1/0}; $line .= ",$add"; } } print "$line\n"; __DATA__ # --> Here, the data with two record blocks you presented just above
And this processes your two record blocks and prints:
436906901235,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV- +1/1/1/0,CFNRC-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/91436903000 436906901231,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV- +1/1/1/0,CFNRC-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/91436903000
This is presumably what you want, except for the number at the end of the line, which is discussed just below.
Also the 91436903000 should be 1/1/1/0-436903000
OK, fine, but you're not telling how to derive 436903000 from 91436903000. Should we just remove the first two digits in all cases? Or should we remove 91 when the number starts with 91? Or should we remove any digits until we find 43? Or is it something else? How are we supposed to know if you don't tell us?

So I did not change that, because did not specify the rule to be applied to derive the number you want to print. I guess it is probably fairly easy and you can probably make the change yourself.


In reply to Re^5: Create output from Perl hash by Laurent_R
in thread Create output from Perl hash by gbwien

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.