How do i use perl conditional statements?
-
In short in a similar way to other programming languages. The program below provide a basic example. The use of elsif can also be used as in other languages.
#!/usr/bin/perl $hillary = 6; $eva = 5; if ($hillary gt $eva) { print "Hillary has more oscars than Eva.\n"; } else { print "Eva has more oscars than Hillary.\n"; }
As the equation is true, it prints the first statement. It is always going to be true purely to demonstrate the if/conditional statement structure the values have been hard coded.
$ ./myperl2 Hillary has more oscars than Eva.
© Lightnetics 2024