<div dir="ltr">Sempre tem uma forma diferente:<div><br></div><div><a href="https://gist.github.com/anonymous/6009717">https://gist.github.com/anonymous/6009717</a><br></div><div><br></div><div>não quer dizer que seja melhor ou pior, basta ver se é legivel ou não.</div>

<div><br></div><div>talvez o reduce seja ilegivel, mas se vc utilizar um map talvez fique melhor. </div><div><br></div><div>vai do seu gosto</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/16 Blabos de Blebe <span dir="ltr"><<a href="mailto:blabos@gmail.com" target="_blank">blabos@gmail.com</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Opa,<div><br></div><div>Duas coisas. Na verdade três.</div><div><br></div><div>Seu código tá até bem limpo, seguindo algumas boas práticas até.</div>

<div><br></div><div>...</div>

<div><br></div><div>Mas pode melhorar :)</div><div><br></div><div>Não use bareword para descritor de arquivo, use uma variável. Para lhe apontar a documentação correta "I summon garu".</div>

<div><br></div><div>open my $fh, '<', 'filename.txt' or die 'Cannot open';</div><div><br></div><div>Parêntesis em Perl são opcionais em alguns casos, sendo que usar ou não usar muitas vezes é questão de estilo. Em alguns outros casos são obrigatórios. Na dúvida, use.</div>



<div><br></div><div>...</div><div><br></div><div>Para imprimir hash com elementos em ordem, eu gosto e usar *slice* ao invés de loop.</div><div><br></div><div>my %hash = ( etc => 1, bar => 3, foo => 5)</div>

<div>my @order = qw{ foo bar etc };</div><div>my @ordered_values = @{hash}{ @order };  ## Slice. Chaves a mais de propósito.</div><div>print join( ';', @ordered_values );</div><div><br></div>

<div>Você pode usar o sort por chave:</div><div>my @order = sort { $a cmp $b} keys %hash;</div><div><br></div><div>Note que @order = sort { $a <=> $b} keys %hash;</div><div>Não funciona.</div>

<div><br></div><div>Ou a forma mais curta:</div><div>@order = sort keys %hash;<br></div><div><br></div><div>Ordenando por valor decrescente</div><div>@order = sort { $hash{$b} <=> $hash{$a}} keys %hash;</div>

<div><br></div><div>Novamente, @order = sort { $hash{$b} cmp $hash{$a}} keys %hash;</div><div>Não funciona.</div><div><br></div><div><br></div><div>...</div><div><br></div><div>

Talvez, se o objetivo for só contar e mais nada, usar expressão regular pode ser mais rápido, mas como regexp está fora dos meus domínios então posso estar errado.</div><div><br></div><div>Mede aí e depois conta...</div>



<div><br></div><div><br></div><div>[]'s</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/15 Renato Santos <span dir="ltr"><<a href="mailto:renato.cron@gmail.com" target="_blank">renato.cron@gmail.com</a>></span><br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Acredito que não há motivos para não utilizar o <b>for </b>nesse caso,<div><br></div><div>até porque, não parece ter muitas outras soluções, </div>



<div><br></div><div>se for pra deixar o codigo menor, ficará menos legivel. se for pra aumentar a velocidade, você pode reescrever em alguma linguagem compilada, tipo C, só que vai dar mais trabalho!</div>


<div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/15 Rafael Silveira <span dir="ltr"><<a href="mailto:dev.silveira@yahoo.com" target="_blank">dev.silveira@yahoo.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



<div><div>


<div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Boa noite Renato.</div><div><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">






Na verdade, não importa não!</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">Mas, eu gostaria de fazer da melhor forma possível, inclusive evitar  usar outro for.</div>






<div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">Estava pensando em fazer algo parecido, porém salvar num array, e mandar pro arquivo com um join(' ', $var).</div>






<div><br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">Mas mesmo assim utilizaria o for.</div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">






<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">Muito obrigado a todos! :D</div><span><font color="#888888"><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">






<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:'times new roman','new york',times,serif">[]'s</div>  </font></span></div></div><br></div></div><div>

=begin disclaimer<br>



   Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
 SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
 L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
=end disclaimer<br>
<br></div></blockquote></div><div><br><br clear="all"><div><br></div>-- <br><div><span style="color:rgb(51,51,51);font-size:x-small">Saravá,</span></div><div><span style="color:rgb(51,51,51);font-size:x-small">Renato CRON</span></div>






<div><div style="text-align:right"><font size="1" color="#333333"><a href="http://www.renatocron.com/blog/" target="_blank">http://www.renatocron.com/blog/</a></font></div></div><div style="text-align:right"><font size="1" color="#333333"><a href="http://twitter.com/#!/renato_cron" target="_blank">@renato_cron</a></font></div>







</div></div></div>
<br>=begin disclaimer<br>
   Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
 SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
 L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
=end disclaimer<br>
<br></blockquote></div><br></div>
</div></div><br>=begin disclaimer<br>
   Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
 SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org">SaoPaulo-pm@pm.org</a><br>
 L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
=end disclaimer<br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Tiago B. Peczenyj<br>Linux User #405772<br><br><a href="http://about.me/peczenyj" target="_blank">http://about.me/peczenyj</a>
</div>