in reply to Re^2: Copying files from one file to another file
in thread Copying files from one file to another file
Try something like:
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.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"], }
Give a man a fish: <%-{-{-{-<
|
|---|