<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Oi,<DIV><BR><DIV><DIV>On 2007/04/09, at 17:21, Víctor A. Rodríguez wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">-----BEGIN PGP SIGNED MESSAGE-----</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hash: SHA1</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Olá,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Igor Sutton Lopes wrote:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Acredito que vale a pena estudar um pouco os módulos padrão do Perl,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">antes de fazer coisas como esta. Existem os módulos List::Util,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Hash::Util e Scalar::Util. Aqui está a explicação da razão destes</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">módulos existirem (trecho extraído de 'perldoc Scalar::Util':</DIV></BLOCKQUOTE></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Acredito que devo colar denovo o trecho que foi apagado daqui:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>       "Scalar::Util" contains a selection of subroutines that people have</DIV><DIV>       expressed would be nice to have in the perl core, but the usage would</DIV><DIV>       not really be high enough to warrant the use of a keyword, and the size</DIV><DIV>       so small such that being individual extensions would be wasteful.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Acredito que eu não precise traduzir, mas:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>1. estão no core do perl;</DIV><DIV>2. são problemas corriqueiros;</DIV><DIV>3. resolvem problemas comuns.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Gostaria que *alguém* tivesse lido a página manual ou o código do List::Util para ver o que ela proporciona, antes de mais nada.</DIV><BR><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">...</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Minha dica aqui é: leiam a documentação dos módulos que vêm com o</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Perl, aprendam sobre eles, façam apontamentos como 'módulos que</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">gostaria de usar' e coisas do tipo. Anotem em algum lugar o que eles</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">fazem e consultem quando tiverem algum problema. Reservem alguns</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">minutos do seu dia para ler o Perlmonks[2] e ver que tipo de dúvidas</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">as pessoas tem e quais são as suas respostas. Ler sobre problemas</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">diferentes podem dar-lhes soluções para os problemas que possuem.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">A pergunta da Patty foi : "Pessoal.. tem como eu somar elementos ... sem</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">precisar do for?"</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">O exemplo foi com o array do 10 posiçoes, no mais, então a usagem do</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">List::Util acho não e a melhor opcão (se vocé tem o array maior então</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">uma bõa opcão e usar Perlmonks, CPAN e outros).</DIV></BLOCKQUOTE><BR></DIV><DIV>Certo. Então:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>&lt;code&gt;</DIV><DIV>use List::Util qw(sum);</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>my @array = (1 .. 10);</DIV><DIV>my $resultado = sum(@array);</DIV><DIV>&lt;/code&gt;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>é pior que:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>&lt;code&gt;</DIV><DIV>my @array = (1 .. 10);</DIV><DIV>my $resultado;</DIV><DIV>$resultado += $_ for @array;</DIV><DIV>&lt;/code&gt;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Agora eu estou começando a entender a razão que *todo* o mundo que não conhece perl fica com medo de fazê-lo, argumentando que código perl é *write once*.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Gostaria de ver os argumentos de quem afirma que a segunda opção -ou variação- é melhor do que a primeira, em aspectos de performance, legibilidade, etc.</DIV><BR><DIV> <SPAN class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Lucida Grande; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><DIV>--</DIV><DIV>Igor Sutton</DIV><DIV><A href="mailto:igor.sutton@gmail.com">igor.sutton@gmail.com</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR class="Apple-interchange-newline"></SPAN> </DIV><BR></DIV></BODY></HTML>