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

Hello tye,
and thanks for this code.

I do have a question : what does the eval do ?

I tried to play with $key->{$name} and got a lot of hash references.
The eval does bring the name of the key to delete. Why ?

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

Thanks if you can shed some light ,
Z.

Replies are listed 'Best First'.
Re^3: Removing keys in the registry (code)
by tye (Sage) on Aug 25, 2005 at 22:38 UTC
    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        

      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