Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Array interpolation in Rakudo

by Anonymous Monk
on Aug 10, 2010 at 08:07 UTC ( #853975=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Shouldn't arrays be interpolated in print/say statements.

In Perl 5 ..

use strict; use warnings; my @array = ( 1 , 2 , 3 , 4 ); print "The array is @array"; perl ../../programs/ The array is 1 2 3 4

In Perl 6 and rakudo ..

use v6; my @array = ( 1 , 2 , 3 , 4 ); say "The array is @array"; ./perl6 ../../programs/ The array is @array

Bug? Or wrong understanding on my part?

Comment on Array interpolation in Rakudo
Select or Download Code
Replies are listed 'Best First'.
Re: Array interpolation in Rakudo
by moritz (Cardinal) on Aug 10, 2010 at 08:21 UTC
    The language has changed in that respect - arrays and hashes only interpolate into double-quoted strings if they end in a postcircumfix, that is any bracketing characters coming after an expression.
    say "array: @array"; # interpolates nothing say "array: @array[]"; # interpolate all elements say "array: @array[1]"; # interpolate one element say "array: @array.sort"; # no interpolation, does not # end with something brackety say "array: @array.sort()"; # interpolates sorted array

    Rakudo implements those cases according to the specification.

    See also: strings, arrays, hashes, S02: Literals (scroll down)

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Array interpolation in Rakudo
by Utilitarian (Vicar) on Aug 10, 2010 at 08:37 UTC
    At the moment Using Perl 6 in the section on interpolation has this to say
    TODO: explain (non-)interpolation of arrays and hashes once Rakudo gets that right
    You are seeing the expected behaviour rather than a bug:
    You may see a bug if you attempt, (haven't got access to Rakudo @ work)
    my @array = ( 1 , 2 , 3 , 4 ); say "The array is {@array}";
    The {} curly braces within double quotes should allow any expression to be interpolated into the string.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://853975]
Approved by Corion
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2015-11-27 20:32 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls