Try this alternative code:
use strict;
use warnings;
use Data::Dumper;
my $hash;
while (<DATA>){
my ($left,$val) = split /=/,$_ or next;
my ($first,@levels) = split /\./,$left;
my $str="\$hash->{$first}";
for my $last_level(@levels){
$str .= "{$last_level}"
}
eval "$str=$val";
}
print Dumper \$hash;
__DATA__
a.b='xyz'
a.c='abc'
d='def'
a.e='ghi'
If using for production, you may want to sanitize the data before the string eval.
Output:
$VAR1 = \{
'a' => {
'e' => 'ghi',
'c' => 'abc',
'b' => 'xyz'
},
'd' => 'def'
};
"Despite my privileged upbringing, I'm actually quite well-balanced. I have a chip on both shoulders." - John Nash