I am reading a file and creating a hash, however I need one of the hash values to contain another (embedded) hash. Here is the code:
sub rd_template
{
my (%mymsg, %msg48, $msg, $key, $val, $msg48, $key48, $val48);
open FH, $opt_f or die "Can't open $opt_f: $!";
while (<FH>)
{
chomp;
($key, $val) = split /=>/;
if ($key == 48)
{
($key48, $val48) = split /=>/;
$msg48{$key48} = $val48;
}
$msg{$key} = $val;
}
close FH or die "Can't close $opt_f: $!";
my @temp = %msg; # testing to see the hash quickly..
print "@temp\n";
}
Here is a sample file, note that where the key 48 in the file and below is where I would like the data read into an embedded hash, any help would be great!:
MTI=>1100
2=>4000000000000001
3=>003000
4=>000000010000
11=>666666
12=>
14=>0404
22=>B00101200041
24=>100
41=>0009
42=>0009000101
48=>
2=>01 02
3=>5555555
Thanks in Advance!
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.