How to find the Minimum of Two Numbers in Perl


How to find the Minimum of Two Numbers in Perl ?

Answer

To find the minimum of two numbers in Perl, you can use the min function from the List::Util module.



✐ Examples

1 Minimum of Two Numbers

In this example,

  1. We use the use List::Util qw(min); statement to import the min function.
  2. We assign values to variables $a and $b.
  3. We use the min function to find the minimum of $a and $b.
  4. We print the minimum value.

Perl Program

# Minimum of Two Numbers
use List::Util qw(min);

my $a = 10;
my $b = 15;
my $min_val = min($a, $b);
print "Minimum of $a and $b is: $min_val\n";

Output

Minimum of 10 and 15 is: 10

Summary

In this tutorial, we learned How to find the Minimum of Two Numbers in Perl language with well detailed examples.




More Perl Comparison Operations Tutorials

  1. How to find the Maximum of Two Numbers in Perl ?
  2. How to find the Minimum of Two Numbers in Perl ?
  3. How to find the Maximum of Three Numbers in Perl ?
  4. How to find the Minimum of Three Numbers in Perl ?