typestar

Indented heredocs in Perl

Multi-line strings with <<~, which strips the indentation so the code stays pretty.

use strict;
use warnings;

my $name = "Ada";
my $greeting = <<~"END";
    Hello, $name!
    Welcome aboard.
    END
print $greeting;

# single quotes: no interpolation
my $raw = <<~'END';
    Sigils like $name stay literal here.
    END
print $raw;

How it works

  1. <<~"END" starts a heredoc that interpolates $name and drops the leading spaces from every line.
  2. The body runs until a line holding only the terminator, which may be indented too.
  3. With single quotes, <<~'END' takes the text literally — sigils like $name stay as typed.

Keywords and builtins used here

The run, in numbers

Lines
15
Characters to type
228
Tokens
55
Three-star pace
75 tpm

At the three-star pace of 75 tokens a minute, this run takes about 44 seconds.

Type this snippet

Step 3 of 3 in Strings, step 15 of 27 in Language basics.

← Previous Next →