in reply to Re^10: Create output from Perl hash
in thread Create output from Perl hash
edited
I am studying your program and one question I would like to ask you is the following. If the line does not match an MSISDN=value pair e.g. MSISDN=433336901235;, I would like to write to the line MSISDN=0 and then to continue processing the next line, but I am not certain how to do that? This scenario could also occur for other entries other than MSISDN but if I can understand how an example would work I could apply this later on to other parts of the code
Looking at the input file again as an example:-
<BEGINFILE> <SUBBEGIN IMSI=231111400010332; MSISDN=433336901235; ..... .. . <BEGINFILE> <SUBBEGIN IMSI=231111400010339; <----MSISDN is missing I would like +to write MSISDN=0 to the output file ... .. .
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";
the output would look something like this
433336901235,....... additional entries
MSISDN=0,....... additional entries
Thanks you, graham
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: Create output from Perl hash
by Laurent_R (Canon) on Feb 20, 2018 at 17:52 UTC | |
by gbwien (Sexton) on Feb 23, 2018 at 22:39 UTC | |
by Laurent_R (Canon) on Feb 24, 2018 at 11:36 UTC | |
by AnomalousMonk (Archbishop) on Feb 24, 2018 at 12:32 UTC | |
by Laurent_R (Canon) on Feb 24, 2018 at 13:22 UTC |