@@ -472,7 +472,7 @@ string
472
472
END
473
473
= end code
474
474
475
- The contents of the heredoc always begin on the next line, so you can (and
475
+ The contents of the I < heredoc > always begin on the next line, so you can (and
476
476
should) finish the line.
477
477
478
478
= begin code :preamble<sub my-escaping-function { $^x }>
@@ -483,7 +483,7 @@ TERMINATOR
483
483
= end code
484
484
485
485
If the terminator is indented, that amount of indention is removed from the
486
- string literals. Therefore this heredoc
486
+ string literals. Therefore this I < heredoc >
487
487
488
488
= begin code
489
489
say q:to/END/;
@@ -503,7 +503,7 @@ some multi line
503
503
504
504
= end code
505
505
506
- Heredocs include the newline from before the terminator.
506
+ I < Heredocs > include the newline from before the terminator.
507
507
508
508
To allow interpolation of variables use the C < qq > form, but you will then have
509
509
to escape metacharacters C < \{ > as well as C < $ > if it is not the sigil for a
@@ -525,6 +525,38 @@ option {
525
525
};
526
526
= end code
527
527
528
+ Some other situations to pay attention to are innocent-looking ones
529
+ where the text looks like a Raku expression. For example, the
530
+ following generates an error:
531
+
532
+ = begin code :lang<text>
533
+ my $title = 'USAFA Class of 1965';
534
+ say qq:to/HERE/;
535
+ <a href='https://usafa-1965.org'>$title</a>
536
+ HERE
537
+ # Output:
538
+ Type Str does not support associative indexing.
539
+ in block <unit> at here.raku line 2
540
+ = end code
541
+
542
+ The right angle bracket makes '$title' look like a hash call
543
+ to Raku when it is actually a Str variable, hence the error message.
544
+ The cure is to enclose the scalar with curly braces:
545
+
546
+ = begin code :lang<text>
547
+ say qq:to/HERE/;
548
+ <a href='https://usafa-1965.org'>{$title}</a>
549
+ HERE
550
+ = end code
551
+
552
+ Because a I < heredoc > can be very long but is stll interpreted by Raku
553
+ as a single line, finding the source of an error can sometimes be
554
+ difficult. One crude way to debug the error is by starting with the
555
+ first visible line in the code and treating is as a I < heredoc > with
556
+ that line only. Then, until you get an error, add each line in turn.
557
+ (Creating a Raku program to do that is left as an exercise for the
558
+ reader.)
559
+
528
560
You can begin multiple Heredocs in the same line.
529
561
530
562
= begin code
0 commit comments