<?xml version="1.0" encoding="windows-1252"?>
<node id="20214" title="OS.pl" created="2000-06-28 17:37:38" updated="2005-08-12 03:22:22">
<type id="1748">
sourcecode</type>
<author id="19724">
Intrepid</author>
<data>
<field name="doctext">
&lt;code&gt;
# ********************************************************
#  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 &amp;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 &lt;BR&gt;&lt;BR&gt;

=cut
&lt;/code&gt;



&lt;HR SIZE=1&gt;
&lt;SAMP&gt;Colorized version left for historical authenticity :-)

&lt;BR&gt; -- was not popular with the Monks.&lt;/SAMP&gt;
&lt;HR SIZE=1&gt;
&lt;body bgcolor="#000000" 
&lt;pre style="color:#f8fcf8; background-color:#000;"&gt;
&lt;font color="#80a0f8"&gt;# ********************************************************&lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  OS.pl&lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  for Perl scripts that need to know the OS&lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  (c)2000,2003 Soren Andersen &lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  This program is Free Software, it may be used, modified&lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  and redistributed under the same terms as Perl itself.&lt;/font&gt;
&lt;font color="#80a0f8"&gt;#  L/M: Friday Aug 01 2003&lt;/font&gt;
&lt;font color="#80a0f8"&gt;# ********************************************************&lt;/font&gt;

&lt;font color="#f8fc60"&gt;&lt;b&gt;sub&lt;/b&gt;&lt;/font&gt;&lt;font color="#40fcf8"&gt; &lt;/font&gt;&lt;font color="#40fcf8"&gt;IsNotWin&lt;/font&gt;&lt;font color="#40fcf8"&gt;    &lt;/font&gt;{
 &lt;font color="#f8fc60"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt; (&lt;font color="#40fcf8"&gt;$^O&lt;/font&gt; &lt;font color="#f8fc60"&gt;&lt;b&gt;and&lt;/b&gt;&lt;/font&gt; &lt;font color="#40fcf8"&gt;$^O&lt;/font&gt; !~&lt;font color="#f8fc60"&gt;&lt;b&gt; /&lt;/b&gt;&lt;/font&gt;&lt;font color="#f8a0a0"&gt;WIN32&lt;/font&gt;&lt;font color="#f8fc60"&gt;&lt;b&gt;/i&lt;/b&gt;&lt;/font&gt;)   {
     &lt;font color="#f8fc60"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#f8a0a0"&gt;1&lt;/font&gt;;
 } &lt;font color="#f8fc60"&gt;&lt;b&gt;elsif&lt;/b&gt;&lt;/font&gt; (&lt;font color="#40fcf8"&gt;$^O&lt;/font&gt; &lt;font color="#f8fc60"&gt;&lt;b&gt;and&lt;/b&gt;&lt;/font&gt; &lt;font color="#40fcf8"&gt;$^O&lt;/font&gt; =~&lt;font color="#f8fc60"&gt;&lt;b&gt; /&lt;/b&gt;&lt;/font&gt;&lt;font color="#f8a0a0"&gt;WIN32&lt;/font&gt;&lt;font color="#f8fc60"&gt;&lt;b&gt;/i&lt;/b&gt;&lt;/font&gt;)      {
     &lt;font color="#f8fc60"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#f8a0a0"&gt;0&lt;/font&gt;;
 } &lt;font color="#f8fc60"&gt;&lt;b&gt;elsif&lt;/b&gt;&lt;/font&gt; (&lt;font color="#f8fc60"&gt;&lt;b&gt;eval&lt;/b&gt;&lt;/font&gt; (&lt;font color="#f8a0a0"&gt;'&lt;/font&gt;&lt;font color="#f8a0a0"&gt;require (&amp;quot;Win32&amp;quot;)&lt;/font&gt;&lt;font color="#f8a0a0"&gt;'&lt;/font&gt;) )  {
     &lt;font color="#f8fc60"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#f8a0a0"&gt;0&lt;/font&gt;;
 }
 &lt;font color="#f8fc60"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/font&gt; &lt;font color="#f8a0a0"&gt;1&lt;/font&gt;;
}
&lt;font color="#f8a0a0"&gt;1&lt;/font&gt;;

&lt;font color="#80a0f8"&gt;__END__&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=head1 NAME OS.pl&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=head1 SYNOPSIS&lt;/font&gt;

&lt;font color="#80a0f8"&gt;Here is one way to use this:&lt;/font&gt;

&lt;font color="#80a0f8"&gt;BEGIN&lt;/font&gt;
&lt;font color="#80a0f8"&gt;{  require (&amp;quot;OS.pl&amp;quot;);&lt;/font&gt;
&lt;font color="#80a0f8"&gt;   if &amp;amp;IsNotWin     {&lt;/font&gt;
&lt;font color="#80a0f8"&gt;       print STDERR &amp;quot;Sorry! This script does not run yet &amp;quot;.&lt;/font&gt;
&lt;font color="#80a0f8"&gt;          &amp;quot;on anything but 32-bit Windows, and &amp;quot;.&lt;/font&gt;
&lt;font color="#80a0f8"&gt;          &amp;quot;you are using $^O\n&amp;quot;;&lt;/font&gt;
&lt;font color="#80a0f8"&gt;    sleep(3);    die;&lt;/font&gt;
&lt;font color="#80a0f8"&gt;   }&lt;/font&gt;
&lt;font color="#80a0f8"&gt;}&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=head1 AUTHOR&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=over 8&lt;/font&gt;

&lt;font color="#80a0f8"&gt;Soren Andersen somian -AT- cpan -DOT- org&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=for html &amp;lt;BR&amp;gt;&amp;lt;BR&amp;gt;&lt;/font&gt;

&lt;font color="#80a0f8"&gt;=cut&lt;/font&gt;
&lt;/pre&gt;


&lt;HR SIZE=1&gt;</field>
<field name="codedescription">
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.</field>
<field name="codecategory">
Win32 Stuff</field>
<field name="codeauthor">
Soren Andersen &lt;somian -AT- pobox *DOT* com&gt;
</field>
</data>
</node>
