Try something like:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my @lines = (
'foo: 12 : //comment twelve ',
'bar: 13 : //comment thirteen',
'foo: 5 : //comment five',
);
;;
my %hash;
for my $line (@lines) {
my ($k, $v) = split qr{ : \s+ }xms, $line, 2;
push @{ $hash{$k} }, $v;
}
dd \%hash;
"
{
bar => ["13 : //comment thirteen"],
foo => ["12 : //comment twelve ", "5 : //comment five"],
}
push-ing to an
@{ ... } array referenced by a hash key
$hash{$k} autovivifies an array reference if it did not already exist. See "autovivification" in
perlglossary and
here.
Give a man a fish: <%-{-{-{-<