Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have a script that is used on Windows and Linux machines. Now, I need to have the script make a registry change on windows. Using Win32::TieRegistry seems reasonable, however I can't figure out a way to have this module work on Windows, and at the same time not get @INC errors on Linux.

My problem, I think, is that Win32::TieRegistry module appears to create a globally-scoped Registry object when the interpreter hits the 'use ...' statement. This object is used in all further interaction with the registry. If I try to put the 'use Win32::TieRegistry' into an 'eval {}', as I do when trying to load modules that may not exist, I get "Global symbol $Registry requires explicit package name..." errors.

Below is a simple script that encapsulates my problem. Two lines are commented out; if either one is uncommented, the script will work on either Windows *or* Linux; but if both are either left alone or uncommented, it fails on both platforms:

#!/usr/bin/perl use strict; my $usemod = 0; eval { require Win32::TieRegistry; }; if ($@) { warn "No module\n"; } else { $usemod = 1; } if ($usemod) { # my ($Registry, $IEKey); # If I expose this line, Windo +ws FAILS ($IEKey remains null); comment out, Windows WORKS # use Win32::TieRegistry(Delimiter=>"/"); # If I expose this line, L +inux FAILS (@INC compile error); comment out, Linux WORKS my $IEKey = $Registry->{'HKEY_CURRENT_USER/Software/Microsoft/Inter +net Explorer/Main/'}; print $IEKey, "\n"; } else { print "None of that stuff here\n"; }

Enlightenment sought, thanks in advance.


In reply to Conditional use of Win32::TieRegistry by hilitai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2021-05-14 14:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?