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


in reply to Conditional use of Win32::TieRegistry

hilitai, with the ideas generated by the other Monks, I was able to come up with this, which worked for me on Win7 strawberry 5.24.1 and linux perl 5.8.5.

#!/usr/bin/perl use strict; use warnings; my $usemod; # if you initialize `my $usemod = 0;`, then the BEGIN +block's assignment to $usemod is overridden, which you don't want our $Registry; # this will be overridden by Win32::TieRegistry's expo +rt of $Registry if in Windows, but BEGIN { local $\ = "\n"; if( $^O eq 'MSWin32' ) { eval { require Win32::TieRegistry; Win32::TieRegistry->import( Delimiter => '/' ); $usemod = 1; } } } if ($usemod) { my $IEKey = $Registry->{'HKEY_CURRENT_USER/Software/Microsoft/Inte +rnet Explorer/Main/'}; print "IEKey = '$IEKey'\n"; } else { print "None of that stuff here\n"; }

edit#2: added use warnings; per best practices

edit#3: added "perl" to "linux perl 5.8.5", so it wasn't implying that was the version of linux, but rather the version of perl