I'm just wondering - is it even possible to create a v-string from a scalar variable without resorting to eval ?
I am. e., this works, but uses eval :
my $var = 'v1.2.3'; my $conversion = to_vstring_1($var);
These two options also work and don't use eval , but instead of "VSTRING" they print "SCALAR":
my $conversion_2 = to_vstring_2($var); # Prints "Version: 1.2.3, type: SCALAR" printf("Version: %vd, type: %s\n", $conversion_2, ref \$conversion_2); my $conversion_3 = to_vstring_3($var); # Prints "Version: 1.2.3, type: SCALAR" printf("Version: %vd, type: %s\n", $conversion_3, ref \$conversion_3); sub to_vstring_2 { my ($arg) = @_; $arg =~ tr/0-9.
So, is there a fourth way to do this?
source share