How to find the Maximum of Two Numbers in Perl


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,

  1. We use the use List::Util qw(max); statement to import the max function.
  2. We declare two variables $a and $b and assign values to them.
  3. We use the max function to find the maximum of $a and $b.
  4. 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.




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 ?