in reply to HTML::Template output to scalar or array

I'm assuming you have a block somewhat like the following?

# ouch open(my $fh, '>', 'data.tmp') or die("open failed: $!"); $template->output(print_to => $fh); close($fh); open(my $fh, '<', 'data.tmp') or die("open failed: $!"); chomp( my @template_txt = <$fh> ); close($fh);

Or maybe you're doing more harm than that even?

# major ouch open(my $fh, '>', 'data.tmp') or die("open failed: $!"); print $fh $template->output(); close($fh); open(my $fh, '<', 'data.tmp') or die("open failed: $!"); chomp( my @template_txt = <$fh> ); close($fh);

Either way, the output() method without the 'print_to' parameter will return the template text as a scalar. If you want each line of the template text to be its own array entry (or all in one scalar), you'd want this:

# one line per array entry, no ouch my @template_txt = split( /\n/, $template->output() ); # all in one scalar, no ouch my $template_txt = $template->output();

update: minor updates to the original 'ouch' possibilities, in order to include the reading of file to array.