http://www.perlmonks.org?node_id=1203276

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

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.