[ABE.pm] Text::Template Q

Faber J. Fedor faber at linuxnj.com
Wed Jul 26 10:26:47 PDT 2006


I'm using Text::Template to print out reports.  All this time, I've been
doing this:

    my $report_destination = \*STDOUT;

    printHeader();


    sub printHeader {

    return if ( is_debug() );
    my $template = new Text::Template ( TYPE => 'FILE',
                                        SOURCE =>
                                        'html.template.header.relret_transparency_report');

    my $text =  $template->fill_in( OUTPUT => $report_destination,
                                    HASH => { port => \$port,
                                              rb   => \$rb   });

    }

and it's been working great. 

I now want to redirect the output to a file, so I thought simply
doing this would work:

    open(OUTFILE, "> $myfile");
    my $report_destination = \*OUTFILE;
    printHeader();

but it doesn't.  What happens is the output does get written to file,
but all of the variables are blank THEN the variables' contents are
written to STDOUT.

If I change the fill in function to this:

    my $text =  $template->fill_in( HASH => { port => \$port,
                                              rb   => \$rb   });

then $text contains all of the text but no variable values.  Upon
quitting the program, the values are written to STDOUT.


Is there some magic about filehandles or scoping that I don't know about?


-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701

http://www.linuxnj.com





More information about the ABE-pm mailing list