$i = 5;
print "{$i*10}";
Sometimes I may need to do things like above,but Perl doesn’t interpret it the way I want,and I can only do it with another variable.Is there a trick?
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.
or
These interpolate a “variable” that is a dereference of a code block that contains a reference of the appropriate type (scalar in the first instance, array in the second).
Another way would be to have a dummy hash that always returns the key as a value:
Another way would be to use the
\N{}character name lookup interface, though this will bind variables from a different location, and at compile time (as well as using string eval, potentially a security issue):(This might work better if the charnames handler returned an overloaded proxy object that performed the eval upon stringification, but I don’t have time to try it.)
Yet another way would be to set a string-constant handler with overload::constant().