How to convert 0 into string in Perl?
Last Updated :
30 Nov, 2022
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
my $x = 0;
print qq("$x") ;
|
Approach 2: By concatenation with an empty String
Perl
my $x = 0;
my $st = q[] . $x ;
print qq("$st") ;
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...