Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print v-string?

Tags:

perl

how to print v-string?

our $VERSION = v2.1;
print "$VERSION\n\n";

prints smileys. ☻☺

like image 938
waghso Avatar asked Feb 11 '15 05:02

waghso


2 Answers

What do you mean by print v-strings? What output do you want?

You could do this:

printf "%vd", $VERSION;  # prints "2.1"

or this:

print version::->parse($VERSION)->stringify; # prints "v2.1"

or this:

print version::->parse($VERSION)->normal; # prints "v2.1.0"

or this:

print version::->parse($VERSION)->numify; # prints "2.001000"

Or (best choice of all) you could just avoid using v-strings altogether.

like image 91
ysth Avatar answered Nov 20 '22 12:11

ysth


In Simpler terms, V-Strings are used to convert ASCII numbers to characters.

For example, if we need to print a string "car" using V-String, we need to lookup ASCII value for each character in ASCII table (http://www.asciitable.com/)

c = 99,a = 97,r = 114

So,

$var  = v99.97.114;
print("$var \n");

The above statement will print "car"

like image 3
Rajesh Kumar Raj Avatar answered Nov 20 '22 12:11

Rajesh Kumar Raj