Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Win32::TieRegistry and Delimiter

by mumbles (Friar)
on Apr 15, 2002 at 13:24 UTC ( [id://159173]=perlquestion: print w/replies, xml ) Need Help??

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

The Setting:
ActiveState 5.6.1 running on WinNT 4

I have read the documentation for Win32::TieRegistry Win32::TieRegistry
Which I am sure is complete but which I fear I am far too obtuse to understand and so now find I am more confused than ever.

The Problem:
use Win32::TieRegistry( Delimiter=>"/" );
$remoteKey = $Registry->{"//$pserver/LMachine/SYSTEM/CurrentControlSet/Control/Print/Monitors/HP Standard TCP/IP Port/Ports/$portname/"} || die "Can't read the port key on $pserver: $^E\n";;

Note that the key I want to reference is "HP Standard TCP/IP Port".
Since the delimiter is set to "/" I assume Perl is reading this as two seperate keys and returns the die statement "Can't read the port key"
I have tried "//", "\", '//", '\", etc with no luck.

Could someone please point out how to get around this.
I am sure I will kick myself when the obvious is revealed.

Thanks in advance.

Replies are listed 'Best First'.
(tye)Re: Win32::TieRegistry and Delimiter
by tye (Sage) on Apr 15, 2002 at 16:01 UTC

    No, Win32::TieRegistry handles your chosen delimiter being in a key name for only one very restricted situation. Quoting the documentation:

    If you have already called the Perl C<keys> function on the tied hash [or have already called C<MemberNames> on the object] and the hash key string exactly matches one of the strings returned, then no further parsing is done. In other words, if the key string exactly matches the name of a direct subkey with a delimiter appended, then a reference to a hash tied to that subkey is returned [but only if keys or MemberNames has already been called for that tied hash].

    This is only important if you have selected a delimiter other than the system default delimiter and one of the subkey names contains the delimiter you have chosen. This rule allows you to deal with subkeys which contain your chosen delimiter in their name as long as you only traverse subkeys one level at a time and always enumerate the list of members before doing so.

    The main advantage of this is that Perl code which recursively traverses a hash will work on hashes tied to Registry keys even if a non-default delimiter has been selected.

    That is, you could get away with:

    use Win32::TieRegistry( Delimiter=>"/" ); unless( $remoteKey= $Registry->{"//$pserver/LMachine/SYSTEM/" . "CurrentControlSet/Control/Print/Monitors/"} and $remoteKey->SubKeyNames() and $remoteKey= $remoteKey->{"HP Standard TCP/IP Port/"} and $remoteKey= $remoteKey->{"Ports/$portname/"} ) { die "Can't read the port key on $pserver: $^E\n"; }
    But you'd probably be better off just using:
    use Win32::TieRegistry( Delimiter=>"/" ); $remoteKey = $Registry->Open( "##$pserver#LMachine#SYSTEM#" . "CurrentControlSet#Control#Print#Monitors#" . "HP Standard TCP/IP Port#Ports#$portname#", { Delimiter=>"#" } ) or die "Can't read the port key on $pserver: $^E\n";

            - tye (but my friends call me "Tye")
      Excellent.

      Couldn't see it until it was pointed out.

      Thank you.
Re: Win32::TieRegistry and Delimiter
by RMGir (Prior) on Apr 15, 2002 at 14:11 UTC
    Hmmm, have you tried accessing a simpler key to make sure Win32::TieRegistry is working?

    If not, then the delimiter is the least of your worries :)

    But in any case, you're likely to be safer using '\' (or "\\") as your delim, since that's what windows uses, and I'm pretty sure it's not allowed in the key names. Anything else might show up in the keys, as you've already discovered, and foul you up.

    Since you've already tried "\\", I'd think that "W32::TR just not working" is the likeliest case, though.

    Run the simple test and let us know...
    --
    Mike

      Yes, Win32::TieRegistry is working.
      It's used a few times before geting to that point in the script without errors.

      I was hoping not to have to change the delim for that reason and thought there must be an easier workaround.
      Kinda painted myself into a corner I suppose.

      Thanks
Re: Win32::TieRegistry and Delimiter
by extremely (Priest) on Apr 15, 2002 at 15:42 UTC
    In the TCP/IP part maybe try \\\/? Is it interpreted twice along the way?

    --
    $you = new YOU;
    honk() if $you->love(perl)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://159173]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-24 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found