I have written this code to change a key in the registry to a specific path. When a user selects a database , the program is supposed to edit the registry and then launch the program - reading the registry key.

The problem is this.

The menu options will work intermittently. Some times option 1 will work perfectly , and other time option 1 will change the key value to an option 2 value.

What am I doing wrong?

Any help would be greatly appreciated!

Excerpt from the Perl code - Editing the registry
============================================================
print ("Please choose a database to generate a report from.[1-3]\n"); print ("[1] Database1\n"); print ("[2] Database2\n"); print ("[3] Database3\n"); print (">"); $a = <STDIN>; chomp $a; if ($a == "1") { $pathe = "K:\\path1"; } elsif ($a == "2") { $pathe = "K:\\path2"; } elsif ($a == "3") { $pathe = "K:\\path3; } chomp $pathe; use Win32::Registry; $p = "CLSID\\{42DE62C7-AD04-11D1-BE7E-00E0290B0890}\\LocalServer32"; $main::HKEY_CLASSES_ROOT->Open($p, $CurrVer) || die "Open: $!"; $CurrVer->GetValues(\%vals); # get sub keys and value -hash ref foreach $k (keys %vals) { $key = $vals{$k}; } $CurrVer->SetValue("",REG_SZ, "$pathe"); foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[2]\n"; } $p = "CLSID\\{42DE62C7-AD04-11D1-BE7E-00E0290B0890}\\LocalServer32"; $main::HKEY_CLASSES_ROOT->Open($p, $CurrVer) || die "Open: $!"; $CurrVer->GetValues(\%vals); # get sub keys and value -hash ref foreach $k (keys %vals) { $key = $vals{$k}; } $CurrVer->SetValue("",REG_SZ, "$pathe"); foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[2]\n"; } $p = "CLSID\\{E850B195-F118-4C04-9E57-9901CDB7430D}\\LocalServer32"; $main::HKEY_CLASSES_ROOT->Open($p, $CurrVer) || die "Open: $!"; $CurrVer->GetValues(\%vals); # get sub keys and value -hash ref foreach $k (keys %vals) { $key = $vals{$k}; } $CurrVer->SetValue("",REG_SZ, "$pathe"); foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[2]\n"; } $p = "CLSID\\{7C4A7B0C-6055-4551-B870-F112BE54C094}\\LocalServer32"; $main::HKEY_CLASSES_ROOT->Open($p, $CurrVer) || die "Open: $!"; $CurrVer->GetValues(\%vals); # get sub keys and value -hash ref foreach $k (keys %vals) { $key = $vals{$k}; } $CurrVer->SetValue("",REG_SZ, "$pathe"); foreach $k (keys %vals) { $key = $vals{$k}; print "$$key[2]\n"; }
============================================================

Edit by tye, add CODE tags, remove BR tags


In reply to Perl with Windows Registry by jbrown

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.