I just thought that this would be nice to write a small set of tiny modules that will allow to say
use Win2000 qw/SP6a/; or
use Linux;
to require certain (or better) OS version and that would be very consistent with
use 5.6.0;
which requires certain version of perl (or higher)

Implementation of these modules are left as exercise for a reader :)

Courage, the Cowardly Dog.
PS. Something fishy is going on there, or my name is Vadim Konovalov. And it's not.

Replies are listed 'Best First'.
Re: use Win2000; and alike
by jryan (Vicar) on Jun 06, 2002 at 08:12 UTC

    Or, as an simpler API for your suggestion:

    use OS qw(Win2000);

    or

    use OS qw(Debian-Woody);

    As to what you want these modules to do, however, I am completely clueless :)

      While this is cleaner and better than having tons of separate modules it's not really that helpfull. I mean, most usualy you do not want to blow up if you detect a certain OS. You merely want to load a bit different modules, implement something a little different, set a variable accordingly ...

      So IMHO we'de need somethig less "cool". Maybe something like

      use SysInfo qw(RunUnder); if (RunUnder 'Win32') { if (RunUnder 'Win2000+') { print "Running under Win2000 or WinXP\n"; } else { print "Running under some older or more stripped down Windows\n"; } elsif (RunUnder 'Unix') { if (RunUnder 'BSD') { print "Runnind under BDS Unix\n"; } else { print "Running under some other Unix\n" } } else { print "GOK what are you using\n"; }

      It would be cool if perl could optimize out the code that will not be used when compiling the code, but I don't think that matters much. You do not test for the OS you are running under in tight loops.

        Jenda@Krynicky.cz

Re: use Win2000; and alike
by Juerd (Abbot) on Jun 06, 2002 at 08:36 UTC

    use Windows;

    BEGIN { die "This program needs Windows" unless $^O eq 'Win32' }

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      Argh! No! Please please dont do this!

      $^O eq 'Win32'

      Code like this is pervasive and wrong. And not only that but holds back implementing proper Win32 OS identification in future versions of perl. Currently the only real way to determine if you are on a W2k box is code like Determine Windows Type or Version. The fact is that this should _not_ be necessary. Instead Perl should know and return the correct value in $^O. But so many people have _hardcoded_ tests like you (and tadman) do in this example and in the perl distribution that loads of tests will fail if it is ever changed and we (Win32 users) all get stuck with b0rked OS reporting. (Yes I started working on getting $^O to return the correct value and decided it wasnt worth the effort changing all those tests. Shudder. They are everywhere.)

      At very minimum it makes sense to change the above to the much more flexible and forward compatible

      $^O =~/Win32/
      to determine that you are on a Win32 box. But even still this test will _not_ tell you if you are on an XP box or a W98 box or....

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

        You are probably right. I have no way of testing this, but I'll start changing die if $^O eq 'Win32' to die if $^O =~ /win32|dos/i in my scripts ;) (Come to think of it, Windows.pm would allow for a nice no Windows :)

        On $^O knowing the type of Windows: if I recall correctly, $^O is hardcoded into perl, and Windows 95 programs can run under Windows 2000. I may be wrong, though.

        - Yes, I reinvent wheels.
        - Spam: Visit eurotraQ.
        

        Your "forward compatible" test may wind up more convoluted than you think. No matter what you try.

        Give people string identifiers to work with and they will screw up any notion of compatibility. Take a look at what various versions of IE report themselves as sometime to get around bad browser detect code...

      Well, as the original author mentions, it would be nicely consistent with use 5.6.0 for Perl-versions... and anyway, TIMTOWTDI!

      BrotherAde
        Come on, you can figure it out.
        package Windows; use Carp; sub import { croak "This program needs Windows" unless ($^O eq 'Win32'); } sub unimport { croak "This program refuses to use Windows" if ($^O eq 'Win32'); } 1;
Re: use Win2000; and alike
by Steve_p (Priest) on Jun 06, 2002 at 12:31 UTC
    Eeek! I don't want to sound rude, but that is one of the worst ideas I've ever heard. One of the big advantages of using Perl is that it is cross-platform. If I feel like developing a script to read from Oracle, I can write and test it on my Windows machine first, and then move it to UNIX when I really want it to run. And the UNIX I use depends on the project I'm woking on. With Perl, I depend on the fact that what runs on one platform will work on another. An idea like this would turn Perl into the next VB.

      That's true, however, there are cases where the cross-platformness (or is thet cross-platformity? platformitude??) of Perl break down. Try perlport for a couple of examples. I've been bitten myself because alarm() doesn't exist on Win32 platforms...

      BrotherAde
        So are you suggesting having
        use PosixCompliant;
      Perl also can be used for some given platform, and there is no bad having possibility to check whether a script that designed for a special platform is really executed on that platform.
      In general, yes, it is good to write portable scripts, but sometimes it is important to use some local internals that do not exist everywhere

      And why there exist a whole bunch of Win32::* modules, which are no way portable?

      Vadim.

      There are tons of OS specific features that are both widely used and embedded into perl. This hasnt balkanized it onto one platform. And most of those features are UNIX specific. In fact as a solely NT user I come across UNIX specific code all the time, but it pretends to be portable when it isnt.

      Also note that nothing in the OP's idea would change your current practice. Nothing would _force_ you to use the feature.

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

      Didn't you ever heard that sometimes perl can be used for administrative programming, and WMI managing is an example, and this will work for Win2000 and will not for WinNT (there are no such COM objects there) ?
      In this case I can suggest you to read some materials to become a bit more knowledgable person.

      If you don't know about a possibility this does not mean such possibility does not exists.

      Courage, the Cowardly Dog.
      PS. I knew I not gonna like this