I want to interpolate hash reference to string, but this method is not working.
How does one interpolate $self->Test->{text}
?
# $self->Test->{text} contains "test 123 ok"
print "Value is: $self->Test->{text} \n"; # but not working
output:
Test=HASH(0x2948498)->Test->{text}
Method calls won't get interpolated inside double quotes, so you end up with the stringified reference followed by ->Test->{text}
.
The simple way to do it is to take advantage of the fact that print
takes a list of arguments:
print "Value is: ", $self->Test->{text}, "\n";
You could also use concatenation:
print "Value is: " . $self->Test->{text} . "\n";
You could also use the tried-and-true printf
printf "Value is %s\n", $self->Test->{text};
Or you can use this silly trick:
print "Value is: @{ [ $self->Test->{text} ] }\n";