A program that uses the if-else statement. : If « Statement « Perl






A program that uses the if-else statement.

   
#!/usr/local/bin/perl 

print ("Enter a number:\n"); 
$number1 = <STDIN>; 
chop ($number1); 
print ("Enter another number:\n"); 
$number2 = <STDIN>; 
chop ($number2); 
if ($number1 == $number2) { 
    print ("The two numbers are equal.\n"); 
} else { 
    print ("The two numbers are not equal.\n"); 
} 
print ("This is the last line of the program.\n"); 

   
    
    
  








Related examples in the same category

1.A program containing a simple example of an if statement.
2.A program that uses the if-elsif-else statement.
3.Conditional Control Statements
4.Conditional Modifiers and print
5.Conditional Modifiers: The if Modifier
6.Extend the if statement to include an else block
7.If and else
8.If start with - no repeat
9.If statement and integer comparsion
10.If statement in a while statement
11.If statement ladder
12.If statement with else
13.If statement with scalar variable
14.Nest if statement into for loop
15.Perl has a number of string comparison operators you can use in if statements.
16.Plural format and ternary operator
17.Plural message
18.Plural output with if statement
19.The if Construct
20.The if/else Construct
21.The if/elsif/else Construct
22.Use an elsif statement to check if a different condition is true
23.Use if statement to check the integer value
24.Using if statement to check if a variable has been defined
25.Using if statement to check if a variable is zero
26.Using if statement to check the number entered from keyboard
27.Using if statements with relational and equality operators
28.Using the equality-comparison operator to compare two numbers entered at the keyboard.
29.Using the if elsif statement to check the number entered from keyboard
30.if in a while loop
31.if scope
32.if statement
33.if/else statement
34.if/elsif statement