in reply to Re: HTML::Template output to file
in thread HTML::Template output to file

I tried:
print FILE $template->output(print_to);
and
print FILE $template->print_to;
both to no avail.

Any chance you could show me how that should be?

Thanks.

Replies are listed 'Best First'.
Re: Re: Re: HTML::Template output to file
by bart (Canon) on Dec 01, 2002 at 09:52 UTC
    According to the docs, the desired syntax for your application is
    $template->output(print_to => \*FILE);

    In general, the syntax for named parameters is

    func(name => $value, ...); $obj->method(name => $value, ...);
    optionally with a hyphen in front of the name, which makes it look like a command line option (and which should ring the "familiarity" bell); and which makes it stand out a little more:
    func(-name => $value, ...); $obj->method(-name => $value, ...);
    In case you find this baffling: the autoquoting rule for the left hand side of "=>" also applies to barewords preceded with a hyphen. So, (-name => 'value') is interpreted by Perl as ('-name', 'value').

    But, from the source I would gather that HTML::Template doesn't honour this tradition, by which I mean it likely won't recognize $template->output(-print_to => \*FILE); . However, I musty admit I haven't tested it.

Re: Re: Re: HTML::Template output to file
by Anonymous Monk on Dec 01, 2002 at 10:25 UTC
    From the manual to HTML::Template

    ***QUOTE***
    You may optionally supply a filehandle to print to automatically as the template is generated. This may improve performance and lower memory consumption. Example:

    $template->output(print_to => *STDOUT); The return value is undefined when using the ``print_to'' option.
    ***UNQUOTE***

    Karl

      I fear I was guilty in going to the example pages a little too quickly and not having gone back to check the module documentation.

      That having been said I am still at the stage where I find module documentation a little obscure (though I'm improving all the time), and the clarity of the responses I have received here have really helped me further to understand the documentation.

      I simply therefore thank all those who shared their wisdom for their patience, and assure them that their advice was useful to me to an extent far greater than simply 'reading the documentation'.

      Thank you.