Hi my code below which is sanatised and might not work here runs fine reading a file with $1 $2, ie two elements first one is key and second is value into a hash. But now I want to have more than one value I would like $1{key} $2,$3,$4 so I assume hash of arrays.
my $input_file = "dat.txt";
our %dedicated;
open(DATA, "<$input_file" ) or die;
while ( my $line = <DATA> )
{
chomp $line;
my ($a, $b) = split ' ', $line;
$dedicated{$a} = $b;
}
keys %dedicated;
while (my ($k, $v) = each %dedicated ) {
chomp($k, $v);
blah }
}
}
How do I change from reading in and using a hash, to a hash
of arrays on a file like.
names1 john,bob,stu
names2 mike,john,bob
names3 blah. ......
Many thanks
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.