in reply to Windows Version Detection

Well I think you should look into John M. Dlugosz suggestion. Using an API call to do this has got be better than calling ver through a backtick or system() call. On the subject of windows resources though I would strongly suggest you check out www.sysinternals.com probably the most useful set of windows power tools. (I exclude cygwin on purpose :-)

But no matter what you do I cant help but saying that some of your regexen worry me a bit. Like for instance you are using dot unescaped. Personally I might try to come up with a regex that pulled apart the various version strings and then looked them up in a hash. Something like

local $,="\t"; while (<DATA>) { /Windows\s(\w+)\W+Version\s((?:\d+\.?)+)/ && print $1,$2,"\n"; } #Outputs # 98 4.10.1998 # 2000 5.00.2195 # 95 4.00.1111 # NT 3.51 # NT 4.0 __DATA__ Windows 98 [Version 4.10.1998] Microsoft Windows 2000 [Version 5.00.2195] Microsoft Windows 95. [Version 4.00.1111] Windows NT Version 3.51 Windows NT Version 4.0
Now you have WinType and WinVer as $1 and $2 respectively. Anyway just thought it needed to be said.

:-)

Yves
--
You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Replies are listed 'Best First'.
Re: Re: Windows Version Detection
by jlongino (Parson) on Oct 07, 2001 at 10:04 UTC
    D'oh! You're absolutely right about the regexn (escaping periods). I've seen it several times from reading critiques of other nodes. Believe it or not I've been using Perl for 4.5 years and have never had to use regexen more than once or twice. Having complete control over your own input is nice and makes coding so much easier.

    Fortunately, there are patient souls around to remind me. I've been playing the piano for 35 years but am still taking lessons. It keeps me honest.

    I'll pursue both yours and John's leads before I make a decision. I might have to stick with the DOS VER backticks angle due to code size though. The majority of users that will be running this code won't have Perl (thus Perl2exe) and I know that each additional module requirement is going to cause a hit in areas of startup time and memory required.

    The goal is not to make a perfect assessment, but to offer the user a reasonable guess as to which platform they are using (like setting a default for an OS picklist). If they don't know what OS they have, they can't possibly have already installed the correct version of the software this program will be referencing.

    Thanks to both you and John for replying.

    "I have not failed. I've just found 10,000 ways that won't work." -- Thomas Alva Edison