typestar

The say feature in Perl

print with the newline built in, switched on by a feature pragma.

use strict;
use warnings;
use feature 'say';

# say is print with the newline built in
say "no trailing newline needed";

my @scores = (88, 94, 71);
say "scores: @scores";
say "high: ", (sort { $b <=> $a } @scores)[0];

say for map { "item $_" } 1 .. 3;

How it works

  1. use feature 'say' enables the keyword on Perl 5.10 and later.
  2. say interpolates like print but always ends the line for you.
  3. With no argument it prints $_, so say for map makes a tidy list.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
253
Tokens
58
Three-star pace
80 tpm

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

Type this snippet

Step 2 of 3 in Files & modern Perl, step 23 of 27 in Language basics.

← Previous Next →