[ EN | PT ] Using the “print” and “say” functions in Perl | Usando as funções “print” e “say” em Perl

in #linux2 years ago

banner

Read too on Odysee

Read too on Ecency

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 😄🥰



banner

Leia também na Odysee

Leia também na Ecency

Antes de tudo, já aviso que esse texto vai ser muito mais curto que o anterior, mas no próximo vai ter

Depois de ver no artigo anterior sobre como funciona a função print, você deve ter pensado que não tem como simplificar mais. Pensou errado, a partir versão 5 do Perl foi adicionada a função say, que funciona como se fosse uma versão compacta do print (mas adicionando a quebra de linha automaticamente já).

Para usar o comando você primeiro deve definir a versão do Perl. É só você inserir essa linha logo após a hash-bang:

use v5.010;

Após isso, é só você usar em qualquer lugar do arquivo a função say:

say "Hi there!";

E pronto, o efeito dela será o mesmo do seguinte comando:

print "Hi there!\n";

Vou deixar o código completo para vocês poderem comparar com o seu próprio código:

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

E é isso. Bons estudos, e até a próxima aulinha de Perl 😄🥰

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 66795.37
ETH 3087.77
USDT 1.00
SBD 3.72