in reply to Which flavor of Win32?

Consider a lookup table instead of nested if-else blocks:
my %lookup = ( 1 => { 90 => 'Win ME', 10 => 'Win 98', }, 2 => { 3 => 'Win NT 3.51', 4 => 'Win NT 4.0', 5 => { 0 => 'Win 2k', 1 => 'Win XP', }, }, ); my $os = $lookup{$id}->{$minor}; $os = $os->{$major} if $minor == 5; $os ||= 'Unknown Win32s flavor'; print "$os, $major.$minor\n";
UPDATE
Wow - demerphq showed me Determine Windows Type or Version. Just goes to show that both Mr. Muskrat and myself should have done a little searching first. ;)

demerphq++

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: Which flavor of Win32?
by Mr. Muskrat (Canon) on Jun 04, 2002 at 17:12 UTC
    Good point! ++jeffa
    The original had three cases:
    Other Win32s
    Win9x
    WinNT

    While this is definately better than the original, it still requires some work.
    Update: Due to misunderstanding, I will post the original code.
    #!/usr/bin/perl use strict; use warnings; use Win32; my $os; my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion(); $os = "Unknown Win32s flavor" if ($id == 0); $os = "Win9x" if ($id == 1); $os = "WinNT" if ($id == 2); print "$os, version $major.$minor\n";

    Who says that programmers can't work in the Marketing Department?
    Or is that who says that Marketing people can't program?