use strict;
use warnings;
use HTML::TreeBuilder 3;
open(FH, '>', $filename) or die "cannot open file";
select FH;
# ...
# ... everything you print should be redirected to your file
# ...
my $root = HTML::TreeBuilder->new;
$root->parse_file('file2.html');
my @div_class = $root->find_by_attribute("class","forminput");
foreach my $node (@div_class) {
print $node->content_list();
print "\n";
}
close FH;
my $fn='lotr.txt';
open my $fh,'>',$fn or die "Could not open $fn: $!";
print "Three Rings for the Elven-kings under the sky,\n";
print $fh "The Road goes ever on and on\n";
print "Seven for the Dwarf-lords in their halls of stone,\n";
print $fh "Down from the door where it began.\n";
print "Nine for Mortal Men doomed to die,\n";
print $fh "Now far ahead the Road has gone,\n";
print "One for the Dark Lord on his dark throne\n";
print $fh "And I must follow, if I can,\n";
print "In the Land of Mordor where the Shadows lie.\n";
print $fh "Pursuing it with eager feet,\n";
print "One Ring to rule them all, One Ring to find them,\n";
print $fh "Until it joins some larger way\n";
print "One Ring to bring them all and in the darkness bind them\n";
print $fh "Where many paths and errands meet.\n";
print "In the Land of Mordor where the Shadows lie.\n";
print $fh "And whither then? I cannot say.\n";
close $fh;