How to find the Maximum of Two Numbers in Perl - Step by Step Examples
How to find the Maximum of Two Numbers in Perl ?
Answer
To find the maximum of two numbers in Perl, you can use the max function from the List::Util module.
✐ Examples
1 Maximum of Two Numbers
In this example,
- We use the
use List::Util qw(max);
statement to import the max function. - We declare two variables
$a
and$b
and assign values to them. - We use the
max
function to find the maximum of$a
and$b
. - We print the maximum value.
Perl Program
# Maximum of Two Numbers
use strict;
use warnings;
use List::Util qw(max);
my $a = 10;
my $b = 15;
my $max_value = max($a, $b);
print "Maximum of $a and $b is: $max_value\n";
Output
Maximum of 10 and 15 is: 15
Summary
In this tutorial, we learned How to find the Maximum of Two Numbers in Perl language with well detailed examples.