Hello again gbwien,

Try something like this:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub callForwardingsCF { my ($inFile, $outFile) = @_; open (my $fhIn, '<', $inFile) or die "Can not open .'".$inFile."'.: $!"; open (my $fhOut, '>', $outFile) or die "Can not open .'".$outFile."'.: $!"; my %hash = (); my %finalHash = (); my $count = 0; while (<$fhIn>) { chomp; next if (/<BEGINFILE>|<ENDFILE>/); if (/<SUBBEGIN/) { $count = 1; } elsif (/<SUBEND/) { $count = 0; } elsif ($count) { my @tmp = split /=/; chop $tmp[1]; if (/MSISDN/) { $hash{MSISDN} = $tmp[1]; } elsif (/ODBIC/) { $hash{ODBIC} = $tmp[1]; } elsif (/ODBOC/) { $hash{ODBOC} = $tmp[1]; } elsif (/CF/) { my @cf = split /-/, $tmp[1]; if (index($tmp[1], 'CFU-TS10-ACT') != -1){ $hash{'CF'}{$cf[0]} = $tmp[1]; } elsif ((index($tmp[1], 'CFB-TS10-ACT') != -1)){ $hash{'CF'}{$cf[0]} = $tmp[1]; } } } if ($count == 0) { # we finished the first matching part %finalHash = (%finalHash, %hash); if ( exists $hash{MSISDN} and exists $hash{CF}{CFU} and exists $hash{CF}{CFB} ) { print $fhOut Dumper( \%hash ); } # remove current information prepare for next part of lines delete $hash{MSISDN}; delete $hash{CF}; } } close ($fhIn) or warn "Can not close .'".$inFile."'.: $!"; close ($fhOut) or warn "Can not close .'".$outFile."'.: $!"; return \%finalHash; } print Dumper callForwardingsCF('in.txt', 'out.txt'); __END__ $ perl test.pl $VAR1 = { 'CF' => { 'CFU' => 'CFU-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CFB-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO' }, 'MSISDN' => '1234567890' }; $ cat out.txt $VAR1 = { 'CF' => { 'CFU' => 'CFU-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CFB-TS10-ACT-NONE-YES-NO-NONE-YES-65535- +YES-YES-NO-NO-NO-NO-NO-NO-NO-NO' }, 'MSISDN' => '1234567890' };

Since you did not provide us with more than one subsection of your file or desired output I am not able to help you more than that.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re^3: Check multiple lines exist in a record by thanos1983
in thread Check multiple lines exist in a record 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.