use Win32::Registry;

my $PatchRegPath = "SOFTWARE\\Sun Microsystems\\EntSys\\Installer\\Patches";
my $hkey;

$ProductKey = $ARGV[0];
$ProductPatchId = $ARGV[1];

my $RegValue, $RegKey, $value;
my %values;

$HKEY_LOCAL_MACHINE->Open($PatchRegPath,$hkey);

$hkey->GetValues(\%values);

foreach $value (keys(%values))
{
	$RegKey 	= $values{$value}->[0];
	$RegValue 	= $values{$value}->[2];
	if($RegKey eq $ProductKey)
	{
		@PatchIds = split(/\,/,$RegValue);
		foreach $PatchId (@PatchIds)
		{
			
			if($PatchId ne $ProductPatchId)
			{
				push(@newPatchIds,$PatchId);
			}
		}
		break;
	}
}
	
$l = @newPatchIds;
$newList = "";
for($i=0 ; $i<$l ; ++$i)
{
	if($i == 0)
	{
		$newList.=$newPatchIds[$i];
	} else {
		$newList.=",".$newPatchIds[$i];
	}
}

undef $garbage;

$hkey->SetValueEx($ProductKey,$garbage,REG_SZ,$newList);

if($l == 0)
{
	$hkey->DeleteValue($ProductKey);
}

$hkey->Close();