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
use feature 'say'enables the keyword on Perl 5.10 and later.sayinterpolates likeprintbut always ends the line for you.- With no argument it prints
$_, sosay for mapmakes a tidy list.
Keywords and builtins used here
formapmysortuse
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.
Step 2 of 3 in Files & modern Perl, step 23 of 27 in Language basics.