Detect OS

whats the equivalent of detect OS in perl with an if then ?

 platform='uname'
if [[ $platform == 'Linux' ]]; then
   alias ls='ls --color=auto'
elif [[ $platform == 'SunOS' ]]; then
   alias ls='ls -G'
fi

In perl I see

perl -Mstrict -MEnglish -E 'say $OSNAME'

or

print "$^O"
$
$ uname -o
Cygwin
$
$ cat -n myscript.pl
     1  #!/usr/bin/perl -w
     2  use strict;
     3  use English;
     4
     5  my $platform1 = $OSNAME;
     6  print "1) My platform is $platform1\n";
     7
     8  my $platform2 = $^O;
     9  print "2) My platform is $platform2\n";
    10
    11  my $platform3 = `uname -o`;
    12  print "3) My platform is $platform3";
    13
    14  my $platform4 = qx(uname -o);
    15  print "4) My platform is $platform4\n";
    16
    17  if ($platform1 eq 'Linux') {
    18     print "In if branch...\n";
    19  } elsif ($platform1 eq 'SunOS') {
    20     print "In elsif branch...\n";
    21  } else {
    22     print "In else branch...\n";
    23  }
    24
$
$ perl myscript.pl
1) My platform is cygwin
2) My platform is cygwin
3) My platform is Cygwin
4) My platform is Cygwin

In else branch...
$
$
2 Likes