Hi Monks, I have an input file which I am parsing through using a hash to extract values. I've been out of perl for a bit, the following is an example of the input file, maybe you can help?

<BEGINFILE> <SUBBEGIN IMSI=23341400010332; MSISDN=411206901000; CF=CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-NO +-NO-NO; <SUBEND

My perl code below:-

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; #define files my $HSSIN='D:\testproject\HSS-export.txt'; my $sep = ","; my $key1 = 'MSISDN'; my $key2 = 'CF'; my $MSISDN; my $CF; #1. normalise test file open (INFILE, $HSSIN) or die "Cant open input file"; open (OUTFILE,"> $ofile" ) or die "Cant open file"; while (my $myline=<INFILE>) { next if $myline =~ /(<BEGINFILE>)/; #skip first line chop($myline); $myline=~ s/(\t)(.*)/$2/g; #remove all tabs $myline =~ /(<SUBBEGIN)(.*)(<SUBEND)/g; #record start end pos my $line = $2; my %hash = split(/=/,$line); #print Dumper \%hash; if (exists($hash{$key1})) { $MSISDN = $hash{$key1}; #print "$MSISDN\n"; } if (exists($hash{$key2})) { $CF = $hash{$key2}; $CF =~s /(CFU-ALL-PROV|CFB-ALL-PROV|CFNRY-ALL-PROV|CFNRC-AL +L-PROV)-(NONE)(.*)?/$1\-1\/1\/1\/1\/0/; $CF =~s /(CFD-TS10-ACT-|CFU-TS10-ACT-|CFD-TS10-REG-)((91)(\ +d*)?)(.*)/$1$4/; #print "$CF\n"; } } #print $MSISDN,$sep,$CF; close INFILE;

I do not know how to get the output I need? $MSISDN,$CF

 411206901000,CFU-ALL-PROV-NONE-YES-NO-NONE-YES-65535-NO-NO-NO-NO-NO-NO-NO-NO-NO-NO

Thank you, Graham


In reply to Create output from Perl hash 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.