[SP-pm] Forma culta ? Quando usar ?
Bruno Borela
bruno.borela at gmail.com
Wed Nov 12 18:32:28 PST 2008
Daniel,
Do livro "Perl Best Practices" do Damian Conway:
The "break-after-newlines-and-concatenate" approach is fine for a small
> number of lines, but it starts to become inefficient - and ugly - for larger
> chunks of text.
>
> For multiline strings that exceed two lines, use a heredoc:
>
>
> $usage = <<"END_USAGE";
> Usage: $0 <file> [-full] [-o] [-beans]
> Options:
> -full : produce a full dump
> -o : dump in octal
> -beans : source is Java
> END_USAGE
>
>
Ou seja, como regra geral, use heredoc sempre que o texto exceder duas
linhas. Alguém aqui já citou isto, mas acho bom reforçar: sempre que usar
heredoc, use aspas no terminador. Exemplo:
my $variable = <<"END_HEREDOC";
Texto que excede duas linhas:
$texto
END_HEREDOC
Isto deixa evidente para quem ler o código se o heredoc está aceitando
interpolação de variáveis ou não.
[]s,
Bruno
On Wed, Nov 12, 2008 at 9:31 PM, Daniel de Oliveira Mantovani <
daniel.oliveira.mantovani em gmail.com> wrote:
> Estou estudando Documentos "here", e quero saber quando usar e se é forma
> culta e quando usar.
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
>
> (my $variable = <<DONE) =~ s/^\s+//gm;
> Perl é uma das mais populares linguagens de programação web,
> devido à suas capacidades de manipulação de textos e rápido
> ciclo de desenvolvimento.
> DONE
>
> print "$variable\n";
>
> Obrigado gente
> []'s
>
> ( Procuro emprego )
> --
> print
> "\x54\x68\x65\x20\x53\x69\x6c\x65\x6e\x74\x20\x47\x75\x61\x72\x64\x69\x61\x6e",$/
>
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm em pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>
-------------- Pr?xima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/saopaulo-pm/attachments/20081113/6f49ddf3/attachment.html>
More information about the SaoPaulo-pm
mailing list