beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Unless elsif else statement in Perl

By Chaitanya Singh | Filed Under: Perl

unless-elsif-else statement is used when we need to check multiple conditions. In this statement we have only one “unless” and one “else”, however we can have multiple “elsif”. This is how it looks:

unless(condition_1){
   #These statements would execute if
   #condition_1 is false
   statement(s);
}
elsif(condition_2){
   #These statements would execute if
   #condition_1 & condition_2 are true
   statement(s);
}
elsif(condition_3){
   #These statements would execute if
   #condition_1 is true
   #condition_2 is false
   #condition_3 is true
   statement(s);
}
.
.
.
else{
   #if none of the condition is met
   #then these statements gets executed
   statement(s);
}

Example

#!/usr/local/bin/perl

printf "Enter any number:";
$num = <STDIN>;
unless( $num == 100) {
   printf "Number is not 100\n";
}
elsif( $num==100) {
   printf "Number is 100\n";
}
else {
   printf "Entered number is not 100\n";
}

Output:

Enter any number:101
Number is not 100

Enjoyed this post? Try these related posts

  1. If statement in Perl
  2. Loops and loop control statements in Perl
  3. Subroutines in Perl
  4. Unless statement in Perl
  5. if-elsif-else statement in perl
  6. Perl String Escape Sequences

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

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap