in reply to question about using constants

The question you're asking is "Is there any easier way to call a subroutine within doublequotes?". The answer, AFAIK, is no.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: question about using constants
by emilford (Friar) on Feb 02, 2005 at 20:23 UTC
    So then is that all the @{[]} is doing? Beyond finding a cleaner way, I want to also understand the workings of this.
      You're creating an array reference, then dereferencing it. In the process, you're allowed to make any sort of Perl executing code, not just variable interpolation.

      Being right, does not endow the right to be rude; politeness costs nothing.
      Being unknowing, is not the same as being stupid.
      Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
      Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      It really falls under the category of one of those things that is possible but not all that advisable.

      Just because it's possible to say, "Let's interpolate a function: @{[PI]}\n";, I'm not convinced that it's in any way clearer than: "Lets not interpolate: " . PI . "\n";

      In the first example the double-quoted string is parsed for interpolation components. The @{...} is found, and that tells Perl you want to interpolate a reference to an array. And the [....] creates that reference, based on the "...." expression.

      In the second example, you start with a string, concatenate the evaluated expression, and concatenate a newline character. Much simpler, and less work.


      Dave