Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^8: Create output from Perl hash

by gbwien (Sexton)
on Feb 14, 2018 at 13:15 UTC ( #1209134=note: print w/replies, xml ) Need Help??

in reply to Re^7: Create output from Perl hash
in thread Create output from Perl hash

Thanks for the explanation. I would like to remove 91 from the beginning of the string e.g. 91436903000 should be 436903000, I am not sure how your code should be modified to allow for the substitution?

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"; }

Replies are listed 'Best First'.
Re^9: Create output from Perl hash
by Laurent_R (Canon) on Feb 14, 2018 at 15:37 UTC
    To remove the first two digits, try changing this:
    $add =~ s/(\d+)$/1\/1\/1\/$1/;
    to this:
    $add =~ s/\d\d(\d+)$/1\/1\/1\/$1/;
Re^9: Create output from Perl hash
by gbwien (Sexton) on Feb 14, 2018 at 13:30 UTC

    Actually I think this might work>

    $add =~ s/(91)(\d+)?/$2/;
      I had not seen your latest post above when I replied below in Re^9: Create output from Perl hash. Your solution is probably fine if you're guaranteed that the number to be changed always starts with 91.

      BTW, you don't need to put 91 between parentheses (but then have to use $1 instead of $2):

      $add =~ s/91(\d+)?/$1/;


        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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209134]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2018-05-24 19:53 GMT
Find Nodes?
    Voting Booth?