Search code examples
rakustring-interpolation

Perl6: First array element places into string, 2nd fails to place into string


I'm trying to make a new string from array elements thus:

my $truth = "s3://dir/@d[$d1]/$plate/@d[$d1].$plate.delta";

but the issue is that this gives

s3://dir/pgr_9/1/@d[0].1.delta

when it should give

s3://dir/pgr_9/1/pgr_9.1.delta

Why isn't this array element @d[0] interpolating into the string $truth? How can I get it to?


Solution

  • Not sure about the reason (probably $plate.delta is regarded as a method call?), but escaping the dot before delta solves the problem.

    my $plate = 1;
    my $d1 = 0;
    my @d;
    @d[0] = "pgr_9.1";
    
    say "s3://dir/@d[$d1]/$plate/@d[$d1].$plate\.delta";
    

    Output:

    s3://dir/pgr_9.1/1/pgr_9.1.1.delta