Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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/array_interpolation.pl 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/array_interpolationp6.pl The array is @array

Bug? Or wrong understanding on my part?

Comment on Array interpolation in Rakudo
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2015-07-02 14:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (41 votes), past polls