This isn't particularly hard to solve. I typed into the Chatterbox a subroutine that does it when you asked about it there. I guess you ran off before waiting for a reply. It can be as simple as:
sub deleteReg {
my( $key, $name )= @_;
for( eval { keys %{$key->{$name}} } ) {
deleteReg( $key, "$name\\$_" );
}
delete $key->{$name};
}
deleteReg(
$Registry,
"HKEY_LOCAL_MACHINE/SOFTWARE/MyWay/",
);
Here is a more robust and efficient version (though I'm sure some will consider the above use of eval to be more robust and I agree, but I wanted to show an alternative to that):
*isa= \&UNIVERSAL::isa;
sub deleteReg {
my $key= shift @_; # Registry key to delete item from
my $name= shift @_; # Name of item to delete
{
my $item= $key->{$name};
if( ! $item ) {
warn "Can't read $name in ",
$key->Path(), ": $^E\n";
return;
}
if( ref($item) && isa($item,"HASH") ) {
for my $subName ( keys %$item ) {
deleteReg( $item, $subName );
}
}
}
delete $key->{$name}
or warn "Can't delete $name from ",
$key->Path(), ": $^E\n";
}
deleteReg(
$Registry,
"HKEY_LOCAL_MACHINE/SOFTWARE/MyWay/",
);
Another way to do it doesn't bother with values:
sub regDelTree {
my $rootKey= shift @_; # Reg key to del subtree from
my $keyName= shift @_; # Name of key to delete
{
my $key= $rootKey->{$keyName};
if( ! $key ) {
warn "Can't open $keyName in ",
$rootKey->Path(), ": $^E\n";
return;
}
for( $key->SubKeyNames() ) {
regDelTree( $key, "$_\\" );
}
}
delete $rootKey->{$keyName}
or warn "Can't delete $keyName from ",
$rootKey->Path(), ": $^E\n";
}
regDelTree(
$Registry,
"HKEY_LOCAL_MACHINE/SOFTWARE/MyWay/",
);
The main reason that one of these isn't just included in the module is that dealing with errors in a general way in nested code like this is a pain to do well. The above code just punts and uses warn which is reasonable but often isn't what a user of a module would want. I've wanted to add something like this to the module and I will in a future release.
Code untested at this point. Yes, you might have to do a little work yet. (:
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.