Lingy

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

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

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 Publish0x

Reward the author with $0.01 in crypto, and earn yourself as you read!

20% to author / 80% to me.
Rewards are FREE. Publish0x pays them, not you.

Page not displaying correctly?