in reply to Re^2: Interpolation requires a spurious variable. Why?
in thread Interpolation requires a spurious variable. Why?

Why should it be cleaner? It's just another case and depends on the context you want for the inner code.

Instead of a scalar you require a list to be interpolated into a string!

(which also involves the extra complication of setting $" appropiately.)

Cheers Rolf

Replies are listed 'Best First'.
Re^4: Interpolation requires a spurious variable. Why?
by JavaFan (Canon) on Sep 29, 2009 at 10:29 UTC
    It's just another case and depends on the context you want for the inner code.
    Not really.
    "@{[ ... list context ... ]}";
    That's what everyone expects. But:
    "${\(... list context ... )}";
    The reference operator (\) provides list context to its arguments. I've been bitten by this in the past as well.
      ups that's true, I forgot about this, Thx! :)

      Cheers Rolf

Re^4: Interpolation requires a spurious variable. Why?
by moritz (Cardinal) on Sep 24, 2009 at 13:42 UTC

    Update please disregard, I should have read more carefully...

    It's cleaner because it also works when multiple elements are present:

    use strict; use warnings; use 5.010; my ($a, $b) = (4, 5); say "@{ [$a // 2, $b] }"; # 4 5 say "@{\($a // 2, $b) }"; # Not an ARRAY reference at foo.pl l +ine 8.

    The feature of \( LIST ) to return the same as map \$_, LIST is not always intuitive.

    Perl 6 - links to (nearly) everything that is Perl 6.
      Noone suggested @{\ }. That would never work unless you had an array, in which case you don't need this trick at all. @{[ ]} was being compared to ${\ } and/or ${\( )}.