Detecting Whether Your Script Is Running on Windows or UNIX using $^O
#!/usr/bin/perl -w
if (is_windows() ) {
print "We are running under Windows.\n";
}
print "The OS name is $^O\n";
sub is_windows() {
return $^O =~ /^(MS)?Win/;
}
Related examples in the same category