BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

If else statement in Perl

Last Updated: February 7, 2017 by Chaitanya Singh | Filed Under: Perl

In the last tutorial, we learnt about if statements in perl. In this tutorial we will learn about if-else conditional statement. This is how an if-else statement looks:

if(condition) {
   Statement(s);
}
else {
   Statement(s);
}

The statements inside “if” would execute if the condition is true, and the statements inside “else” would execute if the condition is false.

Example:

#!/usr/local/bin/perl

printf "Enter any number:";
$num = <STDIN>;
if( $num >100 ) {
   # This print statement would execute,
   # if the above condition is true
   printf "number is greater than 100\n";
}
else {
   #This print statement would execute,
   #if the given condition is false
   printf "number is less than 100\n";
}

Output:

Enter any number:120
number is greater than 100

Top Related Articles:

  1. Perl Variables
  2. Until loop in Perl with example
  3. Perl Tutorial for beginners
  4. Installing Perl on Windows, Mac, Linux and Unix
  5. Unless statement in Perl

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Perl Tutorial

  • Perl Tutorial
  • Perl Installation
  • First Perl Program
  • Perl Syntax
  • Data types in Perl
  • Perl Variables
  • my keyword
  • Perl Scalars
  • Use strict and use warnings
  • Perl Arrays
  • Perl Hashes
  • Operators in Perl
  • Perl Conditional statements
  • Perl if
  • Perl if-else
  • Perl if-elsif-else
  • Perl unless
  • Perl unless-else
  • Perl unless-elsif-else
  • Perl switch case
  • Perl given-when-default
  • Perl loops
  • Perl subroutines
  • Perl Strings
  • Perl Escape Sequences

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap