eu prefiro geralmente multiplicar por 1+N casas e usar apenas o numero inteiro,<div><br></div><div>se a quantidade de casas for pequena, *é mais rapido* do que ligar uma lib externa pra processar numeros.</div><div><br></div>

<div>ps: teoricamente é mais rapido, não fiz testes para tal<br><br><div class="gmail_quote">2012/11/29  <span dir="ltr"><<a href="mailto:thiagoglauco@ticursos.net" target="_blank">thiagoglauco@ticursos.net</a>></span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Seu primeiro erro é o operador and. No documento perlop: $ perldoc perlop você vai descobrir o seguinte:<br>
<br>
 " Logical And<br>
     Binary "and" returns the logical conjunction of the two<br>
     surrounding expressions.  It's equivalent to && except for<br>
     the very low precedence.  This means that it short-circuits:<br>
     i.e., the right expression is evaluated only if the left<br>
     expression is true.<br>
[...]<br>
  C-style Logical And<br>
     Binary "&&" performs a short-circuit logical AND operation.<br>
     That is, if the left operand is false, the right operand is<br>
     not even evaluated.  Scalar or list context propagates down<br>
     to the right operand if it is evaluated."<br>
<br>
Logo, seu código<div class="im"><br>
<br>
if($keys >= $min and $keys <= $max){<br>
<br></div>
deveria ser if($keys >= $min && $keys <= $max){<br>
<br>
A segunda coisa é o seu range. Não sei a precisão que seu código precisa. Veja isso:<br>
<br>
 $ perl -E '<br>
if (-30.00000000000000001 >= -30 ){<br>
say "-30.00000000000000001 is equal -30? Really";}<div class="im"><br>
else {<br>
say "Floating Point is not true real"};'<br></div>
-30.00000000000000001 is equal -30? Really<br>
 $<br>
<br>
<br>
Eu faria algo como:<br>
<br>
if($keys > $min and $keys < $max)<br>
<br>
e, usaria, por exemplo -30.000001 como min e -20.000001 como max, por exemplo, para contornar o ponto flutuante, ou usaria um módulo matemático, como o Math::BigFloat.<br>
<br>
<a href="http://perldoc.perl.org/Math/BigFloat.html" target="_blank">http://perldoc.perl.org/Math/<u></u>BigFloat.html</a><br>
<br>
Eu nunca usei em algo que fosse crítico, mas me parece bem sólida e segura.<br>
<br>
<br>
Em 2012-11-29 18:46, Aureliano Guedes escreveu:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Renato, fiquei sem entender, no meu caso não esta fazendo so um loop?<br>
E qual a diferença entre usar um hash %h ou tranformar $h em um hash??<br>
Desculpe as perguntas é que não faço nenhum curso ligado a computação<br>
logo as vezes fico "boiando".<br>
<br>
Thiago, segue o script caso tenha também algo a modificar/acrescentar<br>
a nível das minhas péssimas práticas.<br>
<br>
use warnings;<br>
use strict;<br>
use Path::Class;<br>
<br>
#Guardar os valores em um hash acessado pelo valor do mfe<br>
sub h_energy{<br>
 my $data = shift;<br>
 my $file = file($data)->openr();<br>
 my %hmfe = ();<br>
 my $mirna;<br>
 my $record;<br>
<br>
 while (my $linha = <$file>) {<br>
 if ( $linha =~ m{target:.*} ) {<br>
 $record = $linha . $record if ($record);<br>
 $hmfe{$mirna} = $record if ($mirna);<br>
 $mirna = $+{mirna};<br>
 $record = q() if ($record);<br>
 }<br></div>
 elsif ($linha =~ m{mfe:s+(S+)s+kcal/mol}){<div><div class="h5"><br>
 $mirna = $1;<br>
 $record .= $linha;<br>
 }<br>
 else {<br>
 $record .= $linha;<br>
 }<br>
 }<br>
 return %hmfe;<br>
}<br>
<br>
sub termofilter{<br>
 my ($data, $min, $max) = @_;<br>
 my %d = h_energy($data);<br>
 foreach my $keys (keys %d){<br>
 if($keys >= $min and $keys <= $max){<br>
 print $keys . "n";<br>
 }<br>
 }<br>
}<br>
termofilter("hybrid.txt", "-30", "-20");<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Date: Thu, 29 Nov 2012 17:27:15 -0200<br>
From: <a href="mailto:thiagoglauco@ticursos.net" target="_blank">thiagoglauco@ticursos.net</a><br>
To: <a href="mailto:rio-pm@pm.org" target="_blank">rio-pm@pm.org</a><br>
Subject: Re: [Rio-pm] Chaves de hash<br>
<br>
Onde estou agora o firewall bloqueia o pastebin. Pela sua explicação,<br>
verificar por regex seria uma solução segura. O número sera convertido<br>
para um string e, se a sua regex prevê uma margem segura para a<br>
imprecisão do ponto flutuante na sua aplicação, funciona sem problemas.<br>
<br>
Em 2012-11-29 16:59, Aureliano Guedes escreveu:<br>
> Nossa, aqui virou uma arena de ideias, da para aprender muita coisa<br>
> so lendo.<br>
><br>
> O problema é o seguinte, eu tenho uma lista nesse formato:<br>
><br>
> target: 01010101<br>
> length: 581<br>
> miRNA : hsa-miR-15a<br>
> length: 22<br>
><br>
> mfe: -24.4 kcal/mol<br>
> p-value: 0.334111<br>
><br>
> position 244<br>
> target 5' C UCUCCUGUGGUCUCU G U 3'<br>
> CACA GACCA GUGCUGUU<br>
> GUGU UUGGU CACGACGA<br>
> miRNA 3' AAUA U 5'<br>
><br>
> Conforme este arquivo <a href="http://pastebin.com/9v6WFUT7" target="_blank">http://pastebin.com/9v6WFUT7</a><br>
><br>
> Eu quero filtrar essa lista de acordo com o valor de mfe.<br>
><br>
> Exemplo, se mfe for menor que -30 e maior que -20 esta dentro.<br>
><br>
> Logo fiz da seguinte forma: <a href="http://pastebin.com/Dnhv0Zya" target="_blank">http://pastebin.com/Dnhv0Zya</a><br>
><br>
> Funcionou, o problema era sono. Não percebi que a regex estava<br>
> pegando um espaço.<br>
><br>
> Quanto a usar reais como chave de hash, se eu tiver dois reais iguais<br>
> poderá ser um problema para acessar os valores,<br>
> mas em toda regra existe sua exceção.<br>
><br>
> No meu caso, o que me importa é que mfe esteja no intervalo<br>
> determinado.<br>
><br>
> Caso descordem seria uma honra ler a explicação de qualquer um de<br>
> vocês.<br>
><br>
>> Date: Thu, 29 Nov 2012 16:44:50 -0200<br>
>> From: <a href="mailto:thiagoglauco@ticursos.net" target="_blank">thiagoglauco@ticursos.net</a><br>
>> To: <a href="mailto:rio-pm@pm.org" target="_blank">rio-pm@pm.org</a><br>
>> Subject: Re: [Rio-pm] Chaves de hash<br>
>><br>
>> Um exemplo mais preciso:<br>
>><br>
>> $ uname -a<br>
>> SunOS cg01spo 5.10 Generic_138888-03 sun4v sparc<br>
>> SUNW,SPARC-Enterprise-T5120<br>
>><br>
>> $ perl -E '<br>
>> if (0.2 > 0.19999999999999997){<br>
>> say "0.2 is greater than 0.19999999999999997";}<br>
>> else {<br>
>> say "Floating Point is not true real"};'<br>
>> 0.2 is greater than 0.19999999999999997<br>
>> $<br>
>><br>
>> $ perl -E '<br>
>> if (0.2 > 0.19999999999999998){<br>
>> say "0.2 is greater than 0.19999999999999998";}<br>
>> else {<br>
>> say "Floating Point is not true real"};'<br>
>> Floating Point is not true real<br>
>> $<br>
>><br>
>> Por que é importante saber essas coisas?<br>
>> <a href="http://ta.twi.tudelft.nl/users/vuik/wi211/disasters.html" target="_blank">http://ta.twi.tudelft.nl/<u></u>users/vuik/wi211/disasters.<u></u>html</a><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>><br>
>> Em 2012-11-29 15:13, <a href="mailto:thiagoglauco@ticursos.net" target="_blank">thiagoglauco@ticursos.net</a> escreveu:<br>
>> >> Não se compara reais por igualdade.<br>
>> > Se você tem erro na igualdade, terá nas outras comparações se a<br>
>> > diferença entre os números for menor que o maior acréscimo<br>
>> suportado<br>
>> > pela plataforma:<br>
>> ><br>
>> > $ perl -E '<br>
>> > if (0.2 > 0.<u></u>199999999999999999999999999999<u></u>99999999999999){<br>
>> >> say "0.2 is greater than<br>
>> 0.<u></u>199999999999999999999999999999<u></u>99999999";}<br>
>> >> else {<br>
>> >> say "Floating Point is not true real"};'<br>
>> > Floating Point is not true real<br>
>> > $<br>
>> ><br>
>> > $ perl -E '<br>
>> > if (0.2 > 0.199999){<br>
>> > say "0.2 is greater than 0.199999";}<br>
>> > else {<br>
>> > say "Floating Point is not true real"};'<br>
>> > 0.2 is greater than 0.199999<br>
>> > $<br>
>> ><br>
>> > Então, comparar pontos flutuantes não é seguro. Nem igualdade, nem<br>
>> > maio, nem menor.<br>
>> ><br>
>> > E mais: garanto que se você quer usar um número real como chave de<br>
>> > Hash você tem um problema na análise da lógica do problema que<br>
>> está<br>
>> > enfrentando e como solucioná-lo.<br>
>> ><br>
>> ><br>
>> > Em 2012-11-29 10:36, Blabos de Blebe escreveu:<br>
>> >> Na verdade é o contrário, não?<br>
>> >><br>
>> >> Não se compara reais por igualdade.<br>
>> >><br>
>> >> Se você usa reais como chaves de hash, você tem algum problema...<br>
>> >><br>
>> >> Ao não controlar a representação interna em ponto flutuante, você<br>
>> >> pode<br>
>> >> nunca mais alcançar o valor relacionado à chave, se usar um<br>
>> número<br>
>> >> real como chave, pois qualquer bit diferente, mesmo que<br>
>> arredondando<br>
>> >> no mesmo número vai resultar num cálculo diferente na tabela<br>
>> hash.<br>
>> >><br>
>> >> Igualdade entre númros reais constuma ser definida como algo<br>
>> assim:<br>
>> >><br>
>> >> sub float_equal {<br>
>> >> my ($first, $second) = @_;<br>
>> >> my $threshold = 0.00000001 # arbitrário<br>
>> >> return abs( $first - $second ) < $threshold;<br>
>> >> }<br>
>> >><br>
>> >> Converter para string antes de usar como chave de hash também não<br>
>> me<br>
>> >> parece saudável, pois, embora a string vá funcionar bem no hash,<br>
>> >> você<br>
>> >> não garante que a conversão vai resultar sempre na mesma string,<br>
>> e<br>
>> >> aí<br>
>> >> vc se ferra do mesmo jeito.<br>
>> >><br>
>> >> Por outro lado, se você nunca vai acessar o elemento do hash<br>
>> através<br>
>> >> da chave, um foreach por keys() ou values() vai te retornar os<br>
>> >> valores...<br>
>> >><br>
>> >> Mas aí eu te perguntaria por que rails você está usando hash pra<br>
>> >> isso...<br>
>> >><br>
>> >><br>
>> >><br>
>> >> On Thu, Nov 29, 2012 at 6:47 AM, <<a href="mailto:thiagoglauco@ticursos.net" target="_blank">thiagoglauco@ticursos.net</a>><br>
>> wrote:<br>
>> >>> Existe um problema aqui, diferente da comparação.<br>
>> >>> A comparação de reais é problemática devido a estrutura interna<br>
>> do<br>
>> >>> ponto<br>
>> >>> flutuante. NÃO SE COMPARA REAIS POR MAIOR OU MENOR.Isso não é do<br>
>> >>> Perl, mas<br>
>> >>> das regras de aproximação usada pelos processadores.<br>
>> >>><br>
>> >>> Rounding rules<br>
>> >>><br>
>> >>> The standard defines five rounding rules. The first two round to<br>
>> a<br>
>> >>> nearest<br>
>> >>> value; the others are called directed roundings:<br>
>> >>> Roundings to nearest<br>
>> >>><br>
>> >>> Round to nearest, ties to even – rounds to the nearest value;<br>
>> >>> if the<br>
>> >>> number falls midway it is rounded to the nearest value with an<br>
>> even<br>
>> >>> (zero)<br>
>> >>> least significant bit, which occurs 50% of the time; this is the<br>
>> >>> default for<br>
>> >>> binary floating-point and the recommended default for decimal.<br>
>> >>> Round to nearest, ties away from zero – rounds to the nearest<br>
>> >>> value; if<br>
>> >>> the number falls midway it is rounded to the nearest value above<br>
>> >>> (for<br>
>> >>> positive numbers) or below (for negative numbers); this is<br>
>> intended<br>
>> >>> as an<br>
>> >>> option for decimal floating point.<br>
>> >>><br>
>> >>> Directed roundings<br>
>> >>><br>
>> >>> Round toward 0 – directed rounding towards zero (also known as<br>
>> >>> truncation).<br>
>> >>> Round toward +∞ – directed rounding towards positive infinity<br>
>> >>> (also<br>
>> >>> known as rounding up or ceiling).<br>
>> >>> Round toward −∞ – directed rounding towards negative infinity<br>
>> >>> (also<br>
>> >>> known as rounding down or floor).<br>
>> >>><br>
>> >>> Se a comparação for inevitável, converta o seu número para<br>
>> string e<br>
>> >>> compare<br>
>> >>> ou determine um nível de precisão aceitável e faça bit a bit.<br>
>> >>><br>
>> >>> Em 2012-11-28 21:42, Aureliano Guedes escreveu:<br>
>> >>>><br>
>> >>>> Ola Monges.<br>
>> >>>><br>
>> >>>> Estou com um problema simples mas que não acho a solução.<br>
>> >>>><br>
>> >>>> Eu tenho um hash onde as chaves são valores numericos reais (a<br>
>> >>>> maioria negativo e quase nenhum inteiro).<br>
>> >>>> Estou limitando esses valores por um maximo e um minimo.<br>
>> >>>><br>
>> >>>> foreach my $keys (keys %d) {<br>
>> >>>> if ($keys <= $min and $keys >= $max) {<br>
>> >>>> print "$d{$keys}";<br>
>> >>>> }<br>
>> >>>> }<br>
>> >>>><br>
>> >>>> Problema que não da certo.<br>
>> >>>> Ha algo de errado aqui??<br>
>> >>>><br>
>> >>>> ______________________________<u></u>_________________<br>
>> >>>> Rio-pm mailing list<br>
>> >>>> <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
>> >>>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
>> >>><br>
>> >>><br>
>> >>> ______________________________<u></u>_________________<br>
>> >>> Rio-pm mailing list<br>
>> >>> <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
>> >>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
>> >> ______________________________<u></u>_________________<br>
>> >> Rio-pm mailing list<br>
>> >> <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
>> >> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
>> ><br>
>> > ______________________________<u></u>_________________<br>
>> > Rio-pm mailing list<br>
>> > <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
>> > <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
>><br>
>> ______________________________<u></u>_________________<br>
>> Rio-pm mailing list<br>
>> <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
>> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
><br>
> ______________________________<u></u>_________________<br>
> Rio-pm mailing list<br>
> <a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
> <a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
<br>
______________________________<u></u>_________________<br>
Rio-pm mailing list<br>
<a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
Rio-pm mailing list<br>
<a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a><br>
</div></div></blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<u></u>_________________<br>
Rio-pm mailing list<br>
<a href="mailto:Rio-pm@pm.org" target="_blank">Rio-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/rio-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/rio-pm</a></div></div></blockquote></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><br>
</div>