http://www.perlmonks.org?node_id=1021480


in reply to split string into hash of hashes...

first of all, this is not possible

$hash{'HKEY_LOCAL_MACHINE'}{'SOFTWARE'}{'Vendor'}{'Product'}{'CurrentV +ersion'}{' +Tokens'}{'Encotone'}{'SerialNumberUserAttribute'}=12345; $hash{'HKEY_LOCAL_MACHINE'}{'SOFTWARE'}{'Vendor'}{'Product'}{'CurrentV +ersion'}{' +Tokens'}{'Encotone'}{'SerialNumberUserAttribute'}{'LanMan'}{'Value'}= +"";

a hash-entry can't be 12345 and a hash-ref to {'LanMan'}... at the same time.

consider ... {value}=12345

> Anybody have any ideas?

first step should be to build the mainpath as string with splits and joins.

then eval this string to autovivify this hash, and assign a ref to a $subhash to it.

This $subhash -ref can be populated now with all entries which come.

Cheers Rolf

UPDATE

if you don't like evals build the HoH-path in a loop (line 163)

DB<160> $line='HKEY_LOCAL_MACHINE\SOFTWARE\Vendor\Product\CurrentVer +sion\Tokens\Encotone\SerialNumberUserAttribute=12345' DB<161> ($path,$value)= split /=/, $line DB<162> $subhash=$hash={} DB<163> $subhash = $subhash->{$_} = {} for split /\\/,$path DB<165> $subhash->{value}=$value DB<166> $subhash->{LanMan}{value}="" DB<167> $subhash->{LanMan}{type}="REG_SZ" #... and so on for all sub-entries ... DB<168> $hash => { HKEY_LOCAL_MACHINE => { SOFTWARE => { Vendor => { Product => { CurrentVersion => { Tokens => { Encotone => { "SerialNumberUserAttribute +" => { LanMan => { type => "REG_SZ", value => "" }, value => 12345 }, }, }, }, }, }, }, }, }

now repeat these steps for all paths!

HTH

UPDATE

this might delete older sub-structures from previous paths

DB<163> $subhash = $subhash->{$_} = {} for split /\\/,$path

so better do

$subhash = $subhash->{$_} //= {} for split /\\/,$path