To convert a String to an Integer in Perl, you can use the int()
function.
In this example,
$str
with a string value of "999"
.int()
function to convert it to an integer and store the result in the variable $number
.int()
function converts the string to an integer.$number
using print
.my $str = "999";
my $number = int($str);
print "Integer value: $number\n";
Integer value: 999
In this example,
$str
with a string value of "777"
.int()
function to convert it to an integer and store the result in the variable $number
.int()
function converts the string to an integer.$number
using print
.my $str = "777";
my $number = int($str);
print "Integer value: $number\n";
Integer value: 777
In this tutorial, we learned How to Convert String to Integer in Perl language with well detailed examples.