<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">Olá,<DIV><BR><DIV><DIV>On 2007/04/09, at 16:30, 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; ">Patty,</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; ">Patty Silva wrote:</DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Pessoal.. tem como eu somar elementos numericos de um array?</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">ex:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">@teste=(1,2,4,1,3,1,1,1,4,56,7,8,9);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">somar=1+2+4+1+3....</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">sem precisar do for?</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; ">a map e seu amigo !!</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; ">my $suma;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">map { $suma += $_ } @teste;</DIV></BLOCKQUOTE><BR></DIV><DIV>Acredito que vale a pena estudar um pouco os módulos padrão do Perl, antes de fazer coisas como esta. Existem os módulos List::Util, Hash::Util e Scalar::Util. Aqui está a explicação da razão destes módulos existirem (trecho extraído de 'perldoc Scalar::Util':</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>Agora vem o tradicional momento de perguntar 'se é tão simples, por que usamos um módulo ao invés de usar os equivalentes das maneiras x, y e z?'.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>1. Fazem parte do core do Perl, sendo encontrados em todas as plataformas disponíveis em Perl;</DIV><DIV>2. São mais optimizados que o map, for e amigos;</DIV><DIV>3. Se o core do Perl for modificado, com certeza eles também serão modificados e se beneficiarão das optimizações presentes no Perl.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Outro grande erro é a falta de informação -ou memória- que se tem em relação às diversas soluções modulares em Perl. Lembro-me quando foi tópico anteriormente sobre buscar arquivos em diretórios, e ninguém disse uma única vez 'File::Find', ou 'File::Find::Rule' ou 'File::Finder'. Mas o equívoco não foi somente aqui nesta lista, pois quando fiz uma apresentação[1] para o Lisbon.pm Tech Meeting, perguntei quantos dos presentes conheciam o File::Spec, o File::Path, os File::Find's e a resposta foi decepcionante.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Minha dica aqui é: leiam a documentação dos módulos que vêm com o Perl, aprendam sobre eles, façam apontamentos como 'módulos que gostaria de usar' e coisas do tipo. Anotem em algum lugar o que eles fazem e consultem quando tiverem algum problema. Reservem alguns minutos do seu dia para ler o Perlmonks[2] e ver que tipo de dúvidas as pessoas tem e quais são as suas respostas. Ler sobre problemas diferentes podem dar-lhes soluções para os problemas que possuem.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>[1] <A href="http://lisbon.pm.org/slides/">http://lisbon.pm.org/slides/</A></DIV><DIV>[2] <A href="http://www.perlmonks.org">http://www.perlmonks.org</A>/</DIV><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>