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

I was wondering if one of you helpful monks could point me down the rightous path for a problem I am experiencing with Win32::TieRegistry. The following code snippet does not appear to work with ActivePerl v5.8.0 because the $Registry object does not exist. I can create a reference to the tied hash manually (i.e. $Registry=\%RegHash) but of course this is not an object as it is not blessed. Do I need to bless it, I was under the impression that $Registry should be created automatically.
use Win32::TieRegistry ( TiedHash => '%RegHash' ); foreach $subkey (keys( %{ $Registry->{"HKEY_CLASSES_ROOT\\batfile\\"} +} ) ) { print $subkey . "\n"; }

20030330 - Edit by Corion : Added formatting / code tags

Replies are listed 'Best First'.
Re: Win32::TieRegistry - no object?
by BrowserUk (Patriarch) on Mar 30, 2003 at 21:02 UTC

    You need to read the follow (rather clumbsily phrased) passage from the Tie::Registry pod.

    Note that you will most likely use $Registry instead of using a tied h +ash. $Registry is a reference to a hash that has been tied to the vir +tual root of your computer's Registry [as if, $Registry= \%RegHash]. +So you would use $Registry->{Key} rather than $RegHash{Key} and use k +eys %{$Registry} rather than keys %RegHash, for example.

    In the snippet you show, your tieing the hash %RegHash to the registry, and you would need to use that variable to access the registry.

    Ie. for $subkey (key %RegHash ) { ...

    Or, you need to initialise $Registry as a reference to %RegHash my $Registry = \%RegHash; or, more likely, to some subhash of %RegHash that contains the values you are interested in.

    The other thing to note about these variable names is that they are not predefined or set in stone, they are just example names used in the documentation. You can use any names that you like, but you will need to declare/initialise them before you use them.


    Examine what is said, not who speaks.
    1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
    2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
    3) Any sufficiently advanced technology is indistinguishable from magic.
    Arthur C. Clarke.