[Cascavel-pm] Uso de Template
Patty Silva
ptfzs em yahoo.com.br
Quarta Maio 9 09:20:08 PDT 2007
[]s
Luis Motta Campos <luismottacampos em yahoo.co.uk> escreveu: 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}
_______________________________________________
Cascavel-pm mailing list
Cascavel-pm em pm.org
http://mail.pm.org/mailman/listinfo/cascavel-pm
__________________________________________________
Fale com seus amigos de graça com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: http://mail.pm.org/pipermail/cascavel-pm/attachments/20070509/93869baf/attachment-0001.html
Mais detalhes sobre a lista de discussão Cascavel-pm