Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

OS.pl

by Intrepid (Deacon)
on Jun 28, 2000 at 21:37 UTC ( #20214=sourcecode: print w/ replies, xml ) Need Help??

Category: Win32 Stuff
Author/Contact Info Soren Andersen <somian -AT- pobox *DOT* com>
Description: A work-around for the absence of a defined value in the built-in special variable $^O (platform, Operating System) in some Perls on Win 95/98. In present form, simply determines if the platform is Win32 or not. The usual `require "OS.pl";' statement is all that's needed.
# ********************************************************
#  OS.pl
#  for Perl scripts that need to know the OS
#  (c)2000,2003 Soren Andersen 
#  This program is Free Software, it may be used, modified
#  and redistributed under the same terms as Perl itself.
#  L/M: Friday Aug 01 2003
# ********************************************************

sub IsNotWin    {
 if ($^O and $^O !~ /WIN32/i)   {
     return 1;
 } elsif ($^O and $^O =~ /WIN32/i)      {
     return 0;
 } elsif (eval ('require ("Win32")') )  {
     return 0;
 }
 return 1;
}
1;

__END__

=head1 NAME OS.pl

=head1 SYNOPSIS

Here is one way to use this:

BEGIN
{  require ("OS.pl");
   if &IsNotWin     {
       print STDERR "Sorry! This script does not run yet ".
          "on anything but 32-bit Windows, and ".
          "you are using $^O\n";
    sleep(3);    die;
   }
}

=head1 AUTHOR

=over 8

Soren Andersen somian -AT- cpan -DOT- org

=for html <BR><BR>

=cut

Colorized version left for historical authenticity :-)
-- was not popular with the Monks.

# ******************************************************** # OS.pl # for Perl scripts that need to know the OS # (c)2000,2003 Soren Andersen # This program is Free Software, it may be used, modified # and redistributed under the same terms as Perl itself. # L/M: Friday Aug 01 2003 # ******************************************************** sub IsNotWin { if ($^O and $^O !~ /WIN32/i) { return 1; } elsif ($^O and $^O =~ /WIN32/i) { return 0; } elsif (eval ('require ("Win32")') ) { return 0; } return 1; } 1; __END__ =head1 NAME OS.pl =head1 SYNOPSIS Here is one way to use this: BEGIN { require ("OS.pl"); if &IsNotWin { print STDERR "Sorry! This script does not run yet ". "on anything but 32-bit Windows, and ". "you are using $^O\n"; sleep(3); die; } } =head1 AUTHOR =over 8 Soren Andersen somian -AT- cpan -DOT- org =for html <BR><BR> =cut

Comment on OS.pl
Download Code
RE: OS.pl
by Ovid (Cardinal) on Jun 29, 2000 at 00:07 UTC
    Hmmm... I could use this to print a statement like Sorry, I don't do Windows.

    It's not that my scripts won't run there; I'm just sick of BG and company.

    Update: Aack! Phht!! My first negative post. Sigh...

    Update #2: From some comments that I received (and a negative vote), I realize that I should have clarified the above statement. It was meant simply as a joke. While yes, I get tired of the M$ attitude of "It compiles. Ship it!", I am not really an anti-Microsoft fanatic. I'm just tired of dealing with their bugware and having to code for their "embrace and extend" features. As a programmer, I would prefer that standards be adopted, not companies.

    If I am asked to code in VB or to develop in VBScript, I'll do it. I just prefer universal standards. Coding something that will only work with one company's products just goes against the grain of what I prefer to do.

    That being said, I did appreciate your script and felt it was useful (I voted it ++). I program Perl on both Windows and Linux environments and I can appreciate the need for what you've developed. I'll try to be more careful with my humor in the future :)

    Cheers!

      Ovid wrote:

      Hmmm... I could use this to print a statement like Sorry, I don't do Windows.

      Sure, why not? My posting of this code isn't really about religion or politics or anything. That is, lots of people have strong feelings about M$ and they display a wide gamut of differing emotional temperatures regarding M$ or their products. My basic attitude is this: Windoze is here to stay for a long while, in 'Net years, at a minimum it is going to be a significant presence for a decade (I am no fortune-teller, that's an off-the-cuff best guess).

      This being the case, those who live Close to the Machine (hack, program for love/money) can make a choice about how to deal with it. I am not interested in trying to strong-arm people into accepting any particular well-worked-over dogma or agenda in this realm, but rather simply offer what I have discovered and in the process present my sometimes quirky take on things. Take it or leave it, as with all else that goes on amongst the Monks.

      Knowledge is knowledge. Greater insight into what's going on with Perl on Win32 is fundamentally neutral information; what people chose to do with it (or whether they choose to pay any attention at all) is an individual matter.


      Best regards, Intrepid <soren andersen>

Back to Code Catacombs

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://20214]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (14)
As of 2014-07-29 11:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (214 votes), past polls