#!/bin/perl # SCALARS (continued) print "\nComparison:\n"; print "x\ty\tx == y\tx != y\tx < y\tx > y\tx <= y\tx >= y\n"; $x = 2; $y = 3; print $x, "\t", $y, "\t", ($x == $y), "\t", ($x != $y), "\t", ($x < $y), "\t", ($x > $y), "\t", ($x <= $y), "\t", ($x >= $y), "\n"; $x = 3; $y = 3; print $x, "\t", $y, "\t", ($x == $y), "\t", ($x != $y), "\t", ($x < $y), "\t", ($x > $y), "\t", ($x <= $y), "\t", ($x >= $y), "\n"; $x = 3; $y = 2; print $x, "\t", $y, "\t", ($x == $y), "\t", ($x != $y), "\t", ($x < $y), "\t", ($x > $y), "\t", ($x <= $y), "\t", ($x >= $y), "\n"; print "\n"; #relational operators for strings: eq ne lt gt le ge print "a\tb\ta eq b\ta ne b\ta lt b\ta gt b\ta le b\ta ge b\n"; $a = "hello"; $b = "world"; print $a, "\t", $b, "\t", ($a eq $b), "\t", ($a ne $b), "\t", ($a lt $b), "\t", ($a gt $b), "\t", ($a le $b), "\t", ($a ge $b), "\n"; $a = "hello"; $b = "hello"; print $a, "\t", $b, "\t", ($a eq $b), "\t", ($a ne $b), "\t", ($a lt $b), "\t", ($a gt $b), "\t", ($a le $b), "\t", ($a ge $b), "\n"; $a = "world"; $b = "hello"; print $a, "\t", $b, "\t", ($a eq $b), "\t", ($a ne $b), "\t", ($a lt $b), "\t", ($a gt $b), "\t", ($a le $b), "\t", ($a ge $b), "\n"; print "\nIf, If-else, and Boolean Values:\n"; if (1 < 2) { # CURLY BRACES ALWAYS REQUIRED print "One is less than two.\n"; } if (1 > 2) { print "One is greater than two.\n"; } else { print "One is not greater than two.\n"; } # Four False Cases: if ($var_not_defined) { print "true\n"; } else { print "false\n"; } if (0) { print "true\n"; } else { print "false\n"; } if ('') { print "true\n"; } else { print "false\n"; } if ('0') { print "true\n"; } else { print "false\n"; } # Anything else is true. print "\nLine-input operator :\n"; print "Enter a line:\n"; $line = ; print "Input: [" . $line . "]\n"; chomp($line); # Gets rid of newline at end print "Chomped Input: [" . $line . "]\n"; print "Enter a line:\n"; chomp($line = ); # different form, but common print "Chomped Input: [" . $line . "]\n"; print "\nWhile:\n"; while ($answer ne "yes!") { print "Are we there yet?\n"; chomp($answer = ); }