Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^13: Create output from Perl hash

by gbwien (Sexton)
on Feb 23, 2018 at 22:39 UTC ( #1209873=note: print w/replies, xml ) Need Help??


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

Hi Laurent_R

I do not understand how you set MSISDN=0 in your code, could you please explain it a little more to me? Thank you Graham

Replies are listed 'Best First'.
Re^14: Create output from Perl hash
by Laurent_R (Canon) on Feb 24, 2018 at 11:36 UTC
    Hi gbwien,

    the program I suggested does not set MSISDN=0, it does initialize the beginning of any new output line being built to the string "MSISDN=0". Then, if a line with a MSISDN is found in the input data, the new line beginning is changed to the value found for the MSISDN in the input record; if no MSISDN is found in the input, the initial value is kept and the output line will start with the string "MSISDN=0", which is what you want when there is no MSISDN line in the input.

      the program ... does not set MSISDN=0, it does initialize the beginning of any new output line being built ...

      I haven't been following the slow, tantalizing revelation of the specification of the problem closely enough to know if this is even a possibility, but the code here seems to fail when the first <SUBBEGIN "record" does not contain an MSISDN=n; field, e.g.:

      __DATA__ <BEGINFILE> <SUBBEGIN IMSI=232191400010339; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N +O-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO +-YES-YES-YES-YES-NO; <SUBEND <SUBBEGIN IMSI=232191400010332; MSISDN=436906901235; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N +O-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO +-YES-YES-YES-YES-NO; <SUBEND <BEGINFILE> <SUBBEGIN IMSI=232191400010339; MSISDN=436906901231; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-N +O-NO-NO; CF=CFB-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO- +NO-NO-NO; CF=CFNRY-ALL-PROV-NONE-YES-YES-NONE-YES-65535-NO-NO-NO-NO-NO-NO-N +O-NO-NO-NO; CF=CFNRC-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO +-NO-NO-NO; CF=CFD-TS10-ACT-91436903000-YES-YES-25-YES-65535-YES-YES-NO-NO-NO +-YES-YES-YES-YES-NO; <SUBEND
      which produces the output:
      c:\@Work\Perl\monks\gbwien>perl parse_SUBBEGIN_recs_1.pl ,CFU-ALL-PROV-1/1/1/0,CFB-ALL-PROV-1/1/1/0,CFNRY-ALL-PROV-1/1/1/0,CFNR +C-ALL-PROV-1/1/1/0,CFD-TS10-ACT-1/1/1/436903000 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/436903000 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/436903000
      If this configuration of data is even possible, it seems easy enough to fix by just changing the
          my $line;
      statement just before the  while (<DATA>) { ... } loop to
          my $line = "MSISDN=0";

      (Sorry for any wraparound artifacts!)

      <tangent>
      The use of  <SUBBEGIN and  <SUBEND markers in the data makes me wonder if gbwien is working on a project for the Church of the SubGenius.
      </tangent>


      Give a man a fish:  <%-{-{-{-<

        Yes, AnomalousMonk, you're right.

        The $line variable should be initialized at the time of declaration for the script to work correctly in the event that the first record block does not have an MSISDN line.

        Thanks for the correction.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-09-24 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Eventually, "covfefe" will come to mean:













    Results (192 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!