After reading Master of your Environment (NT), I started looking into OS detection. The faq says to use $^O but it only returns MSWin32 which is not all that helpful. So I turned to the docs for the Win32 module. After a minute or two (or five... I wan't counting), I had some working code in place that while still somewhat lacking, works.
Updated: I have done some further breakdown of the Win32 flavors... Please correct me if I have anything wrong here... I just whipped this up.
Yet to do:
coerce $build into a valid build number...

Note: I did not use $string as it is blank under Win98 and possibly other flavors as well. The docs say this about it: "An arbitrary descriptive string".
Updated once again: I looked into the Config module as well. However, $Config{osname} returns 'MSWin32' same as $^O and $Config{osvers} returns incorrect data (at least on Win 2k).
#!/usr/bin/perl use strict; use warnings; use Win32; # this may be all some people need... print "NT\n" if (Win32::IsWinNT()); print "9x\n" if (Win32::IsWin95()); # others may want to get more indepth... my $os; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion(); $os = "Unknown Win32s flavor" if ($id == 0); if ($id == 1) { if ($minor == 90) { $os = "Win ME"; }elsif ($minor == 10) { $os = "Win 98"; }else{ $os = "Win 95"; } } if ($id == 2) { if ($major == 3) { $os = "Win NT 3.51"; }elsif ($major == 4) { $os = "Win NT 4.0"; }elsif ($major == 5) { if ($minor == 0) { $os = "Win 2k"; }elsif ($minor == 1) { $os = "Win XP"; } }else{ $os = "Unknown NT flavor"; } } print "$os, $major.$minor\n"; BEGIN { if ($^O !~ "Win32") { print "This is not a Win32 system. Exiting...\n"; exit; } }

In reply to Which flavor of Win32? by Mr. Muskrat

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.