Home » Faqs » System » Check os |
There are many special, read-only Perl variables accessible from anywhere in any Perl script. One of them tells you the operating system the script is running in, as the following code demonstrates:
#!/usr/bin/perl use strict; use warnings; my $os = $^O; print "Running in: $os\n"; exit 0;
Under linux the output of this program would be:
Running in: linux
Under windows it would be:
Running in: MSWin32
See perldoc perlvar for more information.