I'm trying to follow the example in the synopsis of HTML::PrettyPrinter
. I corrected the typo to create a FileHandle
:
my $fh = new FileHandle ">E:\\test.html";
Now the file gets created but I'm getting another error:
Can't call method "isa" on an undefined value at C:/Strawberry/perl/site/lib/HTML/PrettyPrinter.pm line 414.
Here is the code I have so far:
use HTML::TreeBuilder;
# generate a HTML syntax tree
my $tree = new HTML::TreeBuilder;
$tree->parse_file("E:\\file.html");
# modify the tree if you want
use HTML::PrettyPrinter;
my $hpp = new HTML::PrettyPrinter ('linelength' => 130,'quote_attr' => 1);
# configure
$hpp->set_force_nl(1,qw(body head)); # for tags
$hpp->set_force_nl(1,qw(@SECTIONS)); # as above
$hpp->set_nl_inside(0,'default!'); # for all tags
# format the source
my $linearray_ref = $hpp->format($tree);
print @$linearray_ref;
# alternative: print directly to filehandle
use FileHandle;
my $fh = new FileHandle ">E:\\test.html";
if (defined $fh) {
$hpp->select($fh);
$hpp->format();
undef $fh;
$hpp->select(undef),
}
use strict; use warnings;
at the top of your script?$hpp->format($tree||die 'no $tree');
?