basics beginner
How to use the say function in Perl 5.10+
Question
What is the difference between print and say in modern Perl, and how do I use say?
The say function was introduced in Perl 5.10 and automatically adds a newline at the end, unlike print. To use it, enable the feature pragma:
use v5.10;
use strict;
use warnings;
# Old way with print
print "Hello World\n";
# Modern way with say
say "Hello World";
# Multiple arguments
say "The answer is: ", 42;
# Output:
# Hello World
# Hello World
# The answer is: 42
The say function is cleaner and reduces the common mistake of forgetting newlines.