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-else statement in Perl

By Chaitanya Singh | Filed Under: Perl

Similar to unless statement, the unless-else statement in Perl behaves opposite to the if-else statement. In unless-else, the statements inside unless gets executed if the condition is false and statements inside else gets executed if the condition is true.

unless(condition) {
   #These statements would execute
   #if the condition is false.
   statement(s);
}
else {
   #These statements would execute
   #if the condition is true.
   statement(s);
}

Example

#!/usr/local/bin/perl

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

Output:

Enter any number:100
number is greater than or equal to 100

Enjoyed this post? Try these related posts

  1. Unless elsif else statement in Perl
  2. Perl String Escape Sequences
  3. While loop in Perl with example
  4. Perl – Lists and Arrays
  5. my keyword – Local and global variables in Perl
  6. given-when-default statement in Perl

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