note
monsieur_champs
<p>Dear fellows<br />
I'm posting this here hopping this can help other monks too.
Guess I was needing a good sleep night.</p>
<p>As soon as I awake this morning, I devised the solution. Its just a matter of making less de-references against the "item" variable, like this:</p>
<readmore>
<code>
[%
USE pessoa_fisica = Class('reciclar::cdbi::pessoa_fisica');
FOREACH item = [ "id", "primeiro_nome", "sobrenome", "display_name", "cep", "nome_logradouro", "numero", "cidade", "estado", "ddd", "telefone" ];
IF $item.defined(); THEN;
#
# Here was my problem.
# I couldn't see that I needed the same construct in
# both sides of the assignment operation, because the
# de-reference operation have different behaviors
# when used inside a hash lookup and alone, in kind
# of "scalar context".
#
params.$item = $item;
END;
END;
IF params.keys(); THEN;
list_pessoa_fisica =
pessoa_fisica.search_where( params, { logic => "and" } );
ELSE;
list_pessoa_fisica = pessoa_fisica.retrieve_all();
END;
%]
</code>
</readmore>
<p>If you pay attention, there is two ways of using the <code>$item</code> construct. First, in "scalar context" (kind of), the result is the transformation of a string in a variable name (and the consequent use of its value in place of the string representing the variable's name). Second, in "hash context" (sorry about the poetic license) when you need to use a variable to name a hash key, in a construct like <code>$hash{$key}</code>, and the interpolation uses the <b>variable name</b> as the hash key (using the same construct used to get a variable's value instead of his name in "scalar context".</p>
<p>I became confuse with those two applications of the same syntatic construct and the mess was done. :-)</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-260843">
<p align="right"><small>-- [monsieur_champs]</small></p>
</div></div>
415917
415917