http://www.perlmonks.org?node_id=1209051

gbwien has asked for the wisdom of the Perl Monks concerning the following question:

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