[Cascavel-pm] Idioma muito legal!!

Luis Campos de Carvalho lechamps em terra.com.br
Quarta Maio 19 13:38:37 CDT 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Gente, eu peguei isso na lista de discussão dos London Perl Mongers, e 
fiquei maravilhado com a beleza da solução!

- ---- Begin Message  ----

 >>>>>>>>>> "Andy" == Andy Armstrong <andy em tagish.com> writes:
Andy> I'm just playing around with some simple Markov
Andy> models so I started to write a script that would
Andy> build arbitrarily deep models. Here it is:

Two thoughts which may both be wrong:

(1) you can't use $a->{3} both as a count and as a deeper hash pointer.
Pick one or the other.

(2) you don't need eval to walk the structure!  Just walk it!
This increments $top->{a}{b}{c}{d}{e}{count}

         $x = $top;
         $x = $x->{$_} ||= {} for qw(a b c d e);
         $x->{count}++;

- -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 
777 0095 <merlyn em stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> 
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See 
PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
- -----End Message -------

   Percebam como o sr. Schwartz percorre um hash de hashes SEM usar EVAL 
(operação demorada e complicada) para incrementar o conteúdo do escalar 
$top->{a}{b}{c}{d}{e}{count}:

         $x = $top;
         $x = $x->{$_} ||= {} for qw(a b c d e);
         $x->{count}++;

   Gente, eu fiquei pensando nas possibilidades, e acabo de chegar à 
conclusão que ainda tenho muito o que aprender sobre Perl...

   Putamplexos!
- --
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   Luis Campos de Carvalho is BSc in Comp Science,
   PerlMonk [SiteDocClan], Cascavel-pm Moderator,
   Unix Sys Admin && Certified Oracle DBA
   http://br.geocities.com/monsieur_champs/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAq6l+z+iwwpKRaDIRAvP5AJ4/uF1n16rXfnMi9Kt18vmzkMaR1ACgi65M
twIJeF1wKquGfynOilVhFK4=
=ISjo
-----END PGP SIGNATURE-----





Mais detalhes sobre a lista de discussão Cascavel-pm