Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

$^O on windows-systems and Perl interna

by esskar (Deacon)
on Jun 16, 2010 at 19:06 UTC ( [id://845088]=perlmeditation: print w/replies, xml ) Need Help??

As we all know, $^O always returns 'MSWin32' on windows based systems. For compatibilty reasons it's good and cannot be changed. But i was wondering whether or not it is possible to bend the Perl interna so that on a windows system, $^O could
  • return ('MSWin32', 'Windows7-32bit-Ultimate') or ('MSWin32', 'WindowsVista-64bit-Professional')
  • return something blessed, that stringfies to 'MSWin32' but also has methods to get better information about the OS (this could also be applied to other os architectures)

Replies are listed 'Best First'.
Re: $^O on windows-systems and Perl interna
by BrowserUk (Patriarch) on Jun 16, 2010 at 19:32 UTC

    Take a look at the Win32 module (which is installed & loaded by default on most windows Perl's).

    print Win32::GetOSVersion();; Service Pack 1 6 0 6001 2 1 0 768 1 print Win32::GetOSName();; WinVista Service Pack 1

    The interpretation of the list from Win32::GetOSVersion() is:

    OS ID MAJOR MINOR Win32s 0 - - Windows 95 1 4 0 Windows 98 1 4 10 Windows Me 1 4 90 Windows NT 3.51 2 3 51 Windows NT 4 2 4 0 Windows 2000 2 5 0 Windows XP 2 5 1 Windows Server 2003 2 5 2 Windows Vista 2 6 0 Windows Server 2008 2 6 0 Windows 7 2 6 1

    Which should be good enough for most purposes.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      i know that there are other ways to get the OS. but my toughts - which are just thoughts and nothing more - could make things easier but i also see that it could confuse other when an scalar suddenly returns an array.
Re: $^O on windows-systems and Perl interna
by Anonymous Monk on Jun 16, 2010 at 19:26 UTC
Re: $^O on windows-systems and Perl interna
by DrHyde (Prior) on Jun 17, 2010 at 09:25 UTC
    As we all know, $^O always returns 'MSWin32' on windows based systems.
    Except when it returns 'cygwin'.
      cygwin runs on windows, it isn't windows based :)
Re: $^O on windows-systems and Perl interna
by sundialsvc4 (Abbot) on Jun 19, 2010 at 01:13 UTC

    I am of the opinion that this sort of determination belongs exactly as it is now:   within the auspices of an appropriately-named module (presumably built-in); and not the Perl language itself. After all, a module can be defined to give you any information that you may want, in any way that you might want to have it, and yet in doing so it remains totally “a black box.” You can have it do whatever it needs to do, without muddying up either the Perl language or, much more importantly, your own code.

    It is always better to have a module that gives you the answer that you want, rather than merely the means with which to figure-out that answer using your own “smarts.” This technique insulates everyone (except the maintainer of the module in question) from any Redmond brainstorm.

Re: $^O on windows-systems and Perl interna
by VinsWorldcom (Prior) on Jun 16, 2010 at 19:33 UTC
    if ($^O eq 'MSWin32') { $ver = `ver`; $ver =~ s/\n//; print "Windows: $ver\n" }
Re: $^O on windows-systems and Perl interna
by Burak (Chaplain) on Jun 17, 2010 at 14:24 UTC
    As we all know, $^O always returns 'MSWin32' on windows based systems.
    I think it'll return "MSWin64" on 64bit Windows. It's better to check for /MSWin/
      I think it'll return "MSWin64" on 64bit Windows.

      So far not:

      C:\test\miniball>perl -E"say $^O" MSWin32 C:\test\miniball>perl -v This is perl, v5.10.1 built for MSWin32-x64-multi-thread
        Ok. It looks like MSWin32 is hardcoded in source files. I also saw that several core modules check only MSWin32. So, even if this is a bug, fixing it does not seem to be worth the trouble :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-28 20:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found