Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2017-01-17 18:08 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (158 votes). Check out past polls.