xuepengduan has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
How to know my program is running on win32 or linux. Some function or module can get the information?
Thanks!
  • Comment on How to know what os the program is running

Replies are listed 'Best First'.
Re: How to know what os the program is running
by tinita (Parson) on Dec 31, 2005 at 13:16 UTC
Re: How to know what os the program is running
by skx (Parson) on Dec 31, 2005 at 13:17 UTC

    You can use the special variable $^O to see what your script is running upon:

    #!/usr/bin/perl -w use strict; print "This is : $^O \n"; if ( $^O =~ /win/i ) { print "Looks like Windows\n"; } if ( $^O =~ /linux/i ) { print "Looks like Linux\n"; }

    (Note: That is "capital o", not "zero".)

    Steve
    --
Re: How to know what os the program is running
by educated_foo (Vicar) on Dec 31, 2005 at 13:42 UTC
    And in the future, you can find answers to questions such as this with "perldoc -q", e.g. perldoc -q 'operating system'.