[SP-pm] descubrir o tipo da variavel

Daniel de Oliveira Mantovani daniel.oliveira.mantovani at gmail.com
Tue Jul 13 03:40:27 PDT 2010


2010/7/13 Thiago Glauco Sanchez <thiagoglauco em ticursos.net>:
> Em 13/07/2010 07:26, Thiago Glauco Sanchez escreveu:
>>
>> Em 13/07/2010 01:32, Andre Carneiro escreveu:
>>>
>>> Seguinte, não tem como você controlar a orderm em que o hash retorna os
>>> itens( pelo menos não de uma maneira simples ). O que vocẽ pode fazer é usar
>>> um template, por exemplo, e lá vc coloca na ordem em que quiser, e preenche
>>> apenas as variáveis.
>>>
>> Na verdade tem sim.
>> com o módulo Tie::IxHash;

Transformar seu Hash em uma variável tipo Tie é muito perigoso, não é
tão simples assim, "Ah... tem um módulo no CPAN que faz.". As coisas
são bem mais complicadas que isso, por dentro do algoritmo ele está
ordenando. Você não sabe quanto de memória/processamento isso está
utilizando.


>>
> Só para ser mais didático.
>
> use Tie::IxHash;
>
> tie %carro, "Tie::IxHash";
> $carro{"Ferrari"} = "Vermelha";
> $carro{"Vectra"}  = "Cinza";
> $carro{"Fox"}  = "Amarelo";
>
> print "Em ordem de inserção:\n";
> for $carro (keys %carro) {
>    print "$carro\n";
> }
>
> print "\nCarro e Cor:\n";
> while (( $carro, $cor ) = each %carro ) {
>    print "$carro $cor.\n";
> }
>
> --
> What is the sound of Perl? Is it not the sound of a wall that people have
> stopped banging their heads against?
> —Larry Wall
>
> Thiago Glauco Sanchez
> Intrutor Perl e Redes
> www.ticursos.net
>
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm em pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm



-- 
http://www.danielmantovani.com

"If you’ve never written anything thoughtful, then you’ve never had
any difficult, important, or interesting thoughts. That’s the secret:
people who don’t write, are people who don’t think."


More information about the SaoPaulo-pm mailing list