Using the “print” and “say” functions in Perl

Using the “print” and “say” functions in Perl

By lingy | Lingy | 1 Aug 2022


banner

First of all, I warn you that this text will be much shorter than the previous one, but in the next one it will be

After seeing the previous article on how the print function works, you must have thought that there is no way to simplify it any further. You thought wrong, from version 5 of Perl the say function was added, which works as if it were a compact version of print (but adding the line break automatically already).

To use the command you must first set the Perl version. Just insert this line right after the hash-bang:

use v5.010;

After that, just use the say function anywhere in the file:

say "Hi there!";

And that's it, the effect of it will be the same as the following command:

print "Hi there!\n";

I'll leave the complete code for you to compare with your own code:

#!/usr/bin/perl
use v5.010;
say "Hi there!";

And that's it. Good studies, and until the next Perl class 😄🥰

How do you rate this article?

2



Lingy
Lingy

My personal blog about technology

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.