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

Deleting_values_or_keys_with_no_subkeys
Clear.
Now I need to delete a node with its subkeys.

I've tried to assign an empty hash ref to this node:

my %blank; $SOURCE->{$folder}=\%blank;
But the node still exists.
Does anybody knows the way to delete node with subkeys, but no recursive deleting its subkeys?
(delete $SOURCE->{$folder} does not works too.)

Edit: g0n - altered display of long URL

  • Comment on Win32::TieRegistry - deleting values or keys with subkeys present.
  • Download Code

Replies are listed 'Best First'.
Re: Win32::TieRegistry - deleting values or keys with subkeys present.
by pKai (Priest) on Jan 19, 2006 at 16:57 UTC

    Assigning a hash to a registry key will only create additional subkeys/values for thoses keys of the right hand side hash, that aren't already a subkey of the left hand side registry key.

    It will not lead to the deletion of subkeys in the left hand side registry key.

    for deleting a subtree you have to get rid of its subkeys, so that delete can proceed.

    Recursively traversing the tree, would do the job.

    # this is only pseudo code # refine and apply at your own risk (of damaging your Registry) sub delkey { my $key = shift; delkey($_) for grep isasubkey($_), keys %$key; delete $key; }

    It's actually more difficult, since you have to make it delete $parent->{$keyname} as described in the docs.

    Good luck!

      As I've understood from your words - there is no way without recursion.
      Ok, I have a search subroutine - it helps me to enumerate subkeys & subnodes.

      Than you for answer.
Re: Win32::TieRegistry - deleting values or keys with subkeys present. (pointer)
by tye (Sage) on Jan 20, 2006 at 01:48 UTC

    Re: Removing keys in the registry (code) covers the topic fairly well. Yes, I need to update the module to address this a little better, even if a I don't come up with the perfect, robust method to add.

    - tye        

Re: Win32::TieRegistry - deleting values or keys with subkeys present.
by Sioln (Sexton) on Jan 20, 2006 at 08:28 UTC
    Done.
    use Win32::TieRegistry; $REMOTE= $Registry->Connect( '127.0.0.1','LMachine',{Delimiter=>"\\"} +) or die; my $key_to_delete="SYSTEM\\RAdmin\\"; my %VALUES; #at %VALUES{FOUND} we will store the nodes &Enum_Nodes_Of_Registry($REMOTE->{$key_to_delete},$key_to_delete); @{$VALUES{FOUND}}=reverse @{$VALUES{FOUND}}; foreach (@{$VALUES{FOUND}}){ print "$_\n"; delete $REMOTE->{$_}; } sub Enum_Nodes_Of_Registry{ my $nested=shift; my $append=shift; push @{$VALUES{FOUND}}, "$append"; foreach (keys %$nested){ if (substr($_,0,1) ne "\\"){ &Enum_Nodes_Of_Registry(${$nested}{$_},"$append$_"); } } }