in reply to RE: Re: Multiple identical keys in a hash.
in thread Multiple identical keys in a hash.
dn=machinename1 name=valueto yield:
$hash{"machinename1"}{"name"}="value";or
$hash{"machinename1"}{"name=value"}=1;in case 1 you should save the different values for name in an array. something like this should work
foreach(@files){ my $dn = ""; open FILE, "$_" or die "error opening $_: ".$!; foreach(<FILE>){ chomp; $dn = $1 if(/dn=(.*)/); push @{$hash{$dn}{$1}}, $2 if(/(^=*)=(.*)/ && $dn ne ""); } close FILE; }if it is case2, I don't know why you would need to add the same line more than once. if you need the number of occurances try :
foreach(<FILE>){ chomp; $dn = $1 if(/dn=(.*)/); $hash{$dn}{$_}++ if(/=)/ && $dn ne ""); }for the inner loop. or use an array for the "name=value" entries:
foreach(<FILE>){ chomp; $dn = $1 if(/dn=(.*)/); push @{$hash{$dn}}, $_ if(/=/ && $dn ne ""); }hope that helps.
|
---|