Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Raku: problem with say() function

by 7stud (Deacon)
on Feb 07, 2024 at 15:30 UTC ( [id://11157600] : perlquestion . print w/replies, xml ) Need Help??

7stud has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

The following code works as expected

use v6; my $name = "Joe"; say "Hello $name"; --output:-- Hello Joe

However, the following code produces an error:

use v6; my $name = "Joe"; say "Hello -->$name<--"; --output:-- ===SORRY!=== Error while compiling /Users/7stud/raku_programs/d.raku Unable to parse quote-words subscript; couldn't find '>' (correspondin +g '<' was at line 4) at /Users/7stud/raku_programs/d.raku:12 ------> <BOL>&#9167;<EOL> expecting any of: postfix

Obviously, there are some characters that cannot appear in a string, but I looked around and I couldn't find any information about that.

Also, in the error message what does the following mean:

------> <BOL>⏏<EOL>

Replies are listed 'Best First'.
Re: Raku: problem with say() function (method?)
by 7stud (Deacon) on Feb 07, 2024 at 15:45 UTC

    Okay, I found a solution in the herdoc docs. I need to do this:

    say "Hello -->{$name}<--";

    According to the heredoc docs:

    The angle bracket to the right of the variable makes it look like a hash index to Raku.

Re: Raku: problem with say() function (method?)
by LanX (Saint) on Feb 07, 2024 at 15:40 UTC
    I'm no Raku user, but I know that the syntax for $hash{key} is now %hash<key> (for non quoted keys).

    It looks like the parser gets confused looking for a hash element inside string interpolation (independent from 'say')

    Maybe try quoting the < with \<

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Thanks Rolf.

      It's a little disconcerting, but the Hash docs don't explain the <> notation. As far as I can tell, it's the same as qw. I found docs on "Word quoting" here.

      say <a b c> eqv ('a', 'b', 'c');   # OUTPUT: «True»

      And, there are some examples at Raku By Example: Hashes:

      say %person-age{'Joan'}; # accessing an element say %person-age<Ben>; # same as above but the quote-words operator