in reply to Re^2: Removing keys in the registry (code)
in thread Removing keys in the registry

what does the eval do ?

If a registry key contains values, then keys will return the names of those values. But $key->{$aValueName} will not give you back a hash reference so the %{$key->{$name}} would fail with "Can't coerce array into hash" or something.

sub deleteReg { my( $key, $name )= @_; for( eval { keys %{$key->{$name}} } ) { deleteReg( $key, "$name\\$_" ); } delete $key->{$name}; }

The eval will return what keys returns if $name is a subkey name and will trap the die and return and empty list if $name is a value name. So for( eval ... ) will silently skip values.

Also after executing this code i end up with a default value in the hive and can't find a way to delete it ?!

You can't have a registry key without an empty default value. That is just the way the registry is.

- tye        

Replies are listed 'Best First'.
Re^4: Removing keys in the registry (code)
by ZlR (Chaplain) on Sep 02, 2005 at 08:50 UTC
    ok i get it :) that's a nice trick .

    You can't have a registry key without an empty default value. That is just the way the registry is.

    yes but what if i wanted to destroy that very "registry folder" after i emptied from all its values ?

      Then just delete the key. (You can't delete a key if it contains subkeys but you can delete a key no matter how many values it has.)

      - tye