·  PERL – Syntax – Operators – Comparison

- Info:

- This tutorial shows how to use comparison operators.

- Procedure:

- Create "PERL Application" Test.pl.

Test.pl

#NUMBERS.--------------------------------------------------------------------

\$left   = 65;

\$right  = 70;

if (\$left == \$right ) { print("Left    equals              right.\n"); }

if (\$left != \$right ) { print("Left is different from      right.\n"); }

if (\$left <  \$right ) { print("Left is smaller   then      right.\n"); }

if (\$left <= \$right ) { print("Left is smaller   or equals right.\n"); }

if (\$left >  \$right ) { print("Left is greater   then      right.\n"); }

if (\$left >= \$right ) { print("Left is greater   or equals right.\n"); }

\$result = \$left <=> \$right;

if ( \$result == -1 ) { print("Left < right.\n"); }

if ( \$result ==  0 ) { print("Left = right.\n"); }

if ( \$result ==  1 ) { print("Left > right.\n"); }

#STRINGS.--------------------------------------------------------------------

\$text  = "Hello";

if (\$text eq "Hello") { print("Text is     equal             to Hello.\n"); }

if (\$text ne "Hell" ) { print("Text is not equal             to Hell. \n"); }

if (\$text lt "Hellp") { print("Text is less    then             Hellp.\n"); }

if (\$text le "Hellp") { print("Text is less    then or equal to Hellp.\n"); }

if (\$text gt "A"    ) { print("Text is greater then             A.\n"    ); }

if (\$text ge "A"    ) { print("Text is greater then or equal to A.\n"    ); }

\$result = \$text <=> "Hellp";

if ( \$result == -1 ) { print("Text < Hellp.\n"); }

if ( \$result ==  0 ) { print("Text = Hellp.\n"); }

if ( \$result ==  1 ) { print("Text > Hellp.\n"); }