[Cascavel-pm] Uso de Template
Luis Motta Campos
luismottacampos em yahoo.co.uk
Quarta Maio 9 05:26:55 PDT 2007
On May 9, 2007, at 2:15 PM, Patty Silva wrote:
> Luis.. :D
> Eu 1 verifico se o arquivo existe...
> se ele existir eu vou "ACRESCENTAR" dados no arquivo
> if(-e "$dirlog/$dir/$log_error")
> {
> print "ARQUIVO EXISTE\n";
> open my $FH1, ">>", $out or die "Nao foi Possivel Abrir o
> Arquivo: $!";
> $t->process( \$input, $ref, $\out ) or die $template->error();
>
>
> }
> else
> {
> print "ARQUIVO NAO EXISTE\n";
> $t->process( \$input, $ref, $out ) or die $template->error();
>
> }
>
> massssss nao funcionou.. ele imprime o nome do arquivo ...
> :D
> o q eu percebi foi que o $t->process( \$input, $ref, $\out ) ele
> cria outro arquivo.. independente de ja existir ou nao...
O manual do Template diz o seguinte:
A third parameter may be passed to the process() method to specify a
different output location. This value may be one of:
* a plain string indicating a file-name which will be opened
(relative to OUTPUT_PATH, if defined) and the output written
to;
* a file GLOB opened ready for output;
* a reference to a scalar (e.g. a text string) to which output/
error is appended;
* a sub routine reference;
* any objetc reference that implements the print() method
Assim, vamos nos aproveitar da segunda alternativa (FILEHANDLE
GLOB), e implementar assim:
# Não precisa mais testar para saber se existe arquivo ou não,
apenas abre em modo APPEND:
open my $FH, '+>', $out
or die "$!";
$template->process( \$input, $ref, $FH )
or die $template->error;
close $FH
or die "$!";
E isso basta para todos os casos.
Por favor tenta ler o manual com mais calma... ;-)
Putamplexos!
--
Luis Motta Campos (a.k.a. Monsieur Champs) is a software engineer,
Perl fanatic evangelist, and amateur {cook, photographer}
Mais detalhes sobre a lista de discussão Cascavel-pm