I Have a html file stored on the disk(The file is This) . I want to remove all the html tags of images. This is what i have tried so far.
#!/usr/bin/perl -w
use HTML::TagFilter;
my $tf = new HTML::TagFilter;
open READ, "D:\\Scripts\\file.html" or die "Couldn't open file: $!";
$string1 = join("", <READ>);
close READ;
my $self = HTML::TagFilter->new(deny => {img => {'all'}});
open (MYFILE, '>D:\\Scripts\\remove.html');
print MYFILE $tf->filter($string1);
close (MYFILE);
If i just run this program it prints
Odd number of elements in anonymous hash at remove everything else.pl line 9.
Parsing of undecoded UTF-8 will give garbage when decoding entities at C:/Perl64
/site/lib/HTML/TagFilter.pm line 499.
The file is stored but it does not have the image tags removed(The line 9 is where i apply the filter). What am i doing wrong here.
First of all you should always
use strictanduse warningsat the start of your program, especially before asking for help to fix it.You have created two
HTML::TagFilterobjects:$tfwhich has no filters and$selfwhich removes<img>elements. You have used$tfto process the HTML so your data is unchanged.This code works, with the corrections I have mentioned and a couple of others.