Open In App

How to convert 0 into string in Perl?

Last Updated : 30 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

First off, in most cases, it doesn’t matter. Perl is usually smart enough to figure out if something’s a string or a number from context. If you have a scalar value that contains a number, you can use it interchangeably as a string or a number based on what operators you use (this is why Perl has different operators for addition and string concatenation).

If you do want to force something to be unambiguously a string, there are many ways to convert an integer into a String in Perl. But here we will discuss how to convert 0 into a String.

Approach 1: By using double quote interpolation

Perl




#program to convert 0 to string
my $x = 0;
print qq("$x")


Output

"0"

Approach 2: By concatenation with an empty String

Perl




#program to convert 0 to String
my $x = 0;
my $st = q[].$x ;
print qq("$st");


Output

"0"

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads