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)
| [reply] [Watch: Dir/Any] [d/l] |
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?
| [reply] [Watch: Dir/Any] [d/l] |
Okay, I did some research (using google mostly) and I found that I do indeed have all the right numbers. And now that I am at home where I have Win 2k, I see that $build is now correct... Can anyone confirm that it is only correct on NT based systems?
I have also taken jeffa's advice and used a lookup table. But, I extended what he wrote a little. Here is the latest version:
#!/usr/bin/perl
use strict;
use warnings;
use Win32;
my ($string, $major, $minor, $build, $id) = Win32::GetOSVersion();
my %lookup = (
1 => {
4 => {
0 => 'Win 95',
3 => 'Win 95 OSR2', # this is new!
10 => 'Win 98',
90 => 'Win ME',
},
},
2 => {
3 => {
51 => 'Win NT 3.51',
},
4 => {
0 => 'Win NT 4.0',
},
5 => {
0 => 'Win 2k',
1 => 'Win XP',
},
},
);
my $os = $lookup{$id}->{$major}->{$minor};
$os ||= 'Unknown Win32s flavor';
print "$os, $major.$minor, build $build";
print ", $string" if ($string ne "");
print "\n";
BEGIN {
if ($^O !~ "Win32") {
print "This is not a Win32 system. Exiting...\n";
exit;
}
}
Updated the code to display build number and $string...
Who says that programmers can't work in the Marketing Department?
Or is that who says that Marketing people can't program?
| [reply] [Watch: Dir/Any] [d/l] |
This node/code is deprecated. Upgrade to Activestate build 633.
Then use Win32::GetOSName()
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look. | [reply] [Watch: Dir/Any] |
Oh, darn!
After I spent all that time! :)
Hmm, after going through the source code for Win32.pm I see that it actually does what I was wanting to do...
Break the Win9x flavors up by build number.
Very nice!
Who says that programmers can't work in the Marketing Department?
Or is that who says that Marketing people can't program?
| [reply] [Watch: Dir/Any] |
In confused what was wrong with Determine Windows Type or Version?
Oh you already said that didnt you. :-) Oops. Sorry.
Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look. | [reply] [Watch: Dir/Any] |
Hmm, how did I miss this before?
Determine Windows Type or Version fits the bill as well.
Who says that programmers can't work in the Marketing Department?
Or is that who says that Marketing people can't program?
| [reply] [Watch: Dir/Any] |
Windows 98 (original)
System Properties shows it as 4.10.1998.
However, the build number is 67766222.
And after doing some more googles, I see that it is correct.
Can someone guide me in the right direction as far as getting perl to know that it's 4.10.1998 (retail, OEM) vs 4.10.2222A (Second Edition)?
Am I blind?
Who says that programmers can't work in the Marketing Department?
Or is that who says that Marketing people can't program?
| [reply] [Watch: Dir/Any] |