In Perl, you can convert an integer to a string using the ""
operator or by using string concatenation.
In this example,
42
to a variable named $num
.""
operator to convert the integer $num
to a string and store the result in the variable $str_num
.""
operator converts the integer to its string representation.# Convert Integer to String using "" Operator
my $num = 42;
my $str_num = "$num";
print "String representation of integer: $str_num\n";
String representation of integer: 42
In this example,
-10
to a variable named $negative_num
.$negative_num
to a string and store the result in the variable $str_negative_num
.# Convert Negative Integer to String using String Concatenation
my $negative_num = -10;
my $str_negative_num = "String representation of negative integer: " . $negative_num;
print $str_negative_num;
String representation of negative integer: -10
In this tutorial, we learned How to Convert Integer to String in Perl language with well detailed examples.