Hello again gbwien,

I am not 100% sure what is the expected output from your description. I took a guess and I put together an example based on the new input and what I think you mean.

Having said that I think the only modifications that you need to add is:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; open (my $fhIn, '<', "in.txt") or die "Can not open 'in.txt': $!"; open (my $fhOut, '>', "out.txt") or die "Can not open 'out.txt': $!"; my %hash = (); my $count = 0; while (<$fhIn>) { chomp; next if (/<BEGINFILE>/); 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], 'CFB-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfbNotSet'; } elsif (index($tmp[1], 'CFU-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfuNotSet'; } elsif (index($tmp[1], 'CFNRY-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfnrnyNotSet'; } elsif (index($tmp[1], 'CFNRC-ALL-PROV-NONE') != -1){ $hash{'CF'}{$cf[0]} = 'CfnrncNotSet'; } else { $hash{'CF'}{$cf[0]} = $tmp[1]; } } } if ($count == 0) { print Dumper \%hash; if (exists $hash{MSISDN}) { say $fhOut "Update Command <".$hash{MSISDN}.">,".$hash{ODBIC}. +",".$hash{ODBOC}.""; } else { say $fhOut "Update Command MSISDN=notSet,".$hash{ODBIC}.",".$h +ash{ODBOC}.""; } delete $hash{MSISDN}; delete $hash{ODBIC}; delete $hash{ODBOC}; delete $hash{CF}; } } close ($fhIn) or warn "Could not close 'in.txt': $!"; close ($fhOut) or warn "Could not close 'out.txt': $!"; __END__ $ perl test.pl $VAR1 = { 'MSISDN' => '431234567893', 'ODBOC' => 'BAOC', 'ODBIC' => 'BAIC', 'CF' => { 'CFNRC' => 'CfnrncNotSet', 'CFB' => 'CfbNotSet', 'CFD' => 'CFD-TS10-ACT-91436903000-YES-YES-25-YES- +65535-YES-YES-NO-NO-NO-YES-YES-YES-YES-NO;', 'CFNRY' => 'CfnrnyNotSet', 'CFU' => 'CfuNotSet' } }; $VAR1 = { 'ODBIC' => 'BICCROSSDOMESTIC', 'ODBOC' => 'BAOC', 'MSISDN' => '431234567899', 'CF' => { 'CFNRY' => 'CfnrnyNotSet', 'CFU' => 'CFU-TS10-ACT-914369050045021-YES-NO-NONE +-YES-65535-YES-YES-NO-NO-NO-NO-NO-NO-NO-NO', 'CFB' => 'CfbNotSet', 'CFNRC' => 'CfnrncNotSet', 'CFD' => 'CFD-TS10-REG-91436903000-YES-YES-25-YES- +65535-YES-YES-NO-NO-NO-YES-YES-YES-YES-NO' } }; $ cat out.txt Update Command <431234567893>,BAIC,BAOC Update Command <431234567899>,BICCROSSDOMESTIC,BAOC

I have not update the concatenation of the string output since I do not know what is the actual output that you are looking for.

In case that this is not the expected way the string should behave, provide an desired output sample so I can understand approximately based on input which fields you want to keep and which you want to skip.

Hope this helps, BR.

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

In reply to Re^3: Grouped Regular Expression not set assign default value by thanos1983
in thread Grouped Regular Expression not set assign default value 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.