Hi.
I have a text file which I've parsed into three elements per line. The following sample snippet of the data, the actual output is thousands of lines.
702005010554291,5016554291,7020000023F22
702005010524898,5016524898,70200000441E0
702005010660208,5016660208,7020000033FD0
702005010509777,5016509777,7020000033FF0
702005010633781,5016633781,7020000024092
702005010616472,5016616472,7020000043FE2
310005010601516,5016601516,7020000044201
702005010526097,5016526097,7020000013EB1
702005010681238,5016681238,7020000044052
702005010551103,5016551103,7020000023F12
702005010625010,5016625010,7020000023F51
I would like to be able to parse the data and create an array/hash for each element in the third row. Eg: an array/hash for 7020000023F22 then 70200000441E0 etc. once it's unique and not repeated. Additionally, I would like to sort and store the element in the second row in the corresponding array/hash if the element in the third row has already been created then the element in the second row is stored in that array/hash. In the end I'd like to have all the elements in the second row stored in the array/hash that corresponds to third element. Not sure if I explain myself properly, I feel like I'm just confusing my own self. LOL
I would really appreciate any help I can get. So far I've have this piece of code but now I need help to sort them out and store them into their respective arrays/hash though.
# Open Data File and parse each line
open my $DF, '<', $DFile or die "Can't open $DFile $!";
foreach $_ (<$DF>){
chomp( $_ );
if((length $_ > 0)&&($_ =~ /^\d{15}/)){
$_ =~ s/\s+/;/g;
my($imsi,$mdn,$sec) = (quotewords('[\t;]+|,\s', 0, $_))[0,
+1,3];
if((($imsi =~ /^\d{15}/)&&($imsi =~ /^(702|310)/))&&(($mdn
+ =~ /^\d{10}/)&&($mdn =~ /^(501)/))){
print $imsi.",".$mdn.",".$sec."\n";
}
}
}
close $DF;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.