[SP-pm] descubrir o tipo da variavel

Thiago Glauco Sanchez thiagoglauco at ticursos.net
Tue Jul 13 03:36:59 PDT 2010


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;
>
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



More information about the SaoPaulo-pm mailing list