related to question: How do I substitute with an evaluated expression in Perl?
In Perl, is there a way like in Ruby to do:
$a = 1;
print "#{$a + 1}";
and it can print out 2?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s a similar shorthand in Perl for this:
This works because the
[]creates a reference to an array containing one element (the result of the calculation), and then the@{}dereferences the array, which inside string interpolation prints each element of the array in sequence. Since there is only one, it just prints the one element.