Given the following file:
department=value1
location=valueA
location=valueB
department=value2
I use the following to load the file into a Perl hash:
use File::Slurp;
use Data::Dumper;
my %hash = map {
s/#.*//;
s/^\s+//;
s/\s+$//;
m/(.*?)\s*=\s*(.*)/;
} read_file($file);
print Dumper(\%hash);
The result, however, is as follows:
$VAR1 = {
'location' => 'valueB',
'department' => 'value2'
};
How can I load the above file into a hash with, say,
$VAR1 = {
'location' => 'valueA,valueB',
'department' => 'value1,value2'
};
Thanks.