perlnewbie2000 has asked for the wisdom of the Perl Monks concerning the following question:

This is my code for now, it looks up the registry entries at HKCU\Software\Microsoft\DevStudio\6.0\Tools and searches for an entry thats called "NumTools" and write the value of it to $NumTools.
use Win32::Registry; my $NumTools; $p = "Software\\Microsoft\\DevStudio\\6.0\\Tools"; $main::HKEY_CURRENT_USER->Open($p, $Tools) || die "Open: $!"; $Tools->GetValues(\%vals); foreach $k (keys %vals) { $key = $vals{$k}; IF ($$key[0] eq "NumTools") { $NumTools = $$key[2]; } }
Now I have to make sure that there is none of the entries that have the value "C:\Tool\Lint\Bin\Lint.exe", but I can't figure out how to put it in an IF sentence. I was thinking of something like:
IF ($$key[2] eq "C:\\Tool\\Lint\\Bin\\Lint.exe") { print "PC-Lint is already installed"; } ELSE {
And then the code below.
Then it has to put in some registry entries if it's true, and they work.
$Tools->SetValueEx("AskArgument#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("CloseWindow#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("DefaultArguments#$NumTools", 0, REG_SZ, ""); $Tools->SetValueEx("GUITool#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("InitialDirectory#$NumTools", 0, REG_SZ, "C:\\Tool\ +\Lint\\Bin"); $Tools->SetValueEx("MenuName#$NumTools", 0, REG_SZ, "PCLint"); $Tools->SetValueEx("OutputRedirect#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("PathName#$NumTools", 0, REG_SZ, "C:\\Tool\\Lint\\B +in\\Lint.exe"); $Tools->SetValueEx("ReloadNoPrompt#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("UseSearchPath#$NumTools", 0, REG_DWORD, "0"); $Tools->SetValueEx("VisibleOnMenu#$NumTools", 0, REG_DWORD, "0"); $NumTools++; $Tools->SetValueEx("NumTools", 0, REG_DWORD, "$NumTools"); }
But somehow it allways comes with the error
syntax error at extract.pl line 9, near ") {"
syntax error at extract.pl line 11, near "}"

that is these 2 lines:
IF ($$key[0] eq "NumTools") { $NumTools = $$key[2]; } }
Can anyone help me figure out what is wrong? Please?

Replies are listed 'Best First'.
Re: registry problems
by holli (Abbot) on Jan 07, 2005 at 08:53 UTC
    "IF" should be "if",
    "ELSE" should be "else"
Re: registry problems
by eyepopslikeamosquito (Archbishop) on Jan 07, 2005 at 09:32 UTC
    The description of Win32::Registry reads "Win32::Registry - accessing the Windows registry (obsolete, use Win32::TieRegistry)". Apart from Win32::Registry being obsolete, Win32::TieRegistry is much easier to use; you simply tie a hash to the registry and access the Registry via the hash.