Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

how do I use Win32::TieRegistry in a multi-platform program?

by perltux (Monk)
on Mar 01, 2018 at 20:17 UTC ( [id://1210183]=perlquestion: print w/replies, xml ) Need Help??

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

If I use Win32::TieRegistry in a program meant to run both on Windows an Linux I get the following error when running it on Linux:

Global symbol "$Registry" requires explicit package name at ./script.pl line 16.
Execution of ./script.pl aborted due to compilation errors.

The code that leads to this is (this is only an extract of a much larger program):
#!/usr/bin/perl use strict; use warnings; my $LINUX; my $WINDOWS; BEGIN{ if ($^O eq 'linux') { $LINUX=1; } elsif ($^O eq 'MSWin32') { $WINDOWS=1; } } use if ($WINDOWS), 'Win32::TieRegistry' => (Delimiter => '/'); if ($WINDOWS) { my $mykey=$Registry->{'HKEY_CURRENT_USER/Control Panel/Desktop/Win +dowMetrics'}; my $wdpi=hex($mykey->{'AppliedDPI'}) .'dpi / '; }


The problem is that $Registry is undefined when this program runs on Linux. How do I solve this?
Many thanks in advance

Replies are listed 'Best First'.
Re: how do I use Win32::TieRegistry in a multi-platform program?
by haukex (Archbishop) on Mar 01, 2018 at 20:47 UTC
      many thanks, I can confirm too that your solution works! I don't know how I missed the other thread, I did search for this (with google) before posting here.
Re: how do I use Win32::TieRegistry in a multi-platform program?
by ikegami (Patriarch) on Mar 04, 2018 at 02:02 UTC

    I'd create a module for each platform, and load the appropriate module.

    sub get_sys_info { if ($^O eq 'Win32') { require My::SystemInfo::Win32; return My::SystemInfo::Win32->new(); } else { require My::SystemInfo::Unix; return My::SystemInfo::Unix->new(); } } my $sys_info = get_sys_info(); ... $sys_info->wdpi ...
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2026-03-10 22:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.