Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I have a command line argument that I've been using on my mac to clean a folder of html files. I've been trying to replicate it using a perl script. Here's the command line code:
find /Users/tlialin/desktop/01282016/Test -type f -name "*.html" -exec + tidy -f errors.txt -m -utf8 -i {} \;
With the help of several here I've been able to get the following perl script together:
use HTML::Tidy; my $call_dir = "Test"; my $contents_of_file = 1; #my $tidy = HTML::Tidy->new(); my $tidy = HTML::Tidy->new({config_file => 'config.txt'}); #my $tidy = HTML::Tidy->new( {config_file => 'path/to/config'} ); my @files = glob "$call_dir/*.html"; printf "Got %d files\n", scalar @files; for my $file (@files) { open my $in_fh, '<', $file or die "Could not open $file : $!"; my $contents_of_file = do { local $/;<$in_fh> }; close $in_fh; $tidy->parse( $file, $contents_of_file ); $tidy->clean( $file); #parse( $filename, $str [, $str...] ) #or warn "Error parsing $file :$!"; for my $message ( $tidy->messages ) { print $message->as_string; } }
It runs and I can see output in terminal but it's hard to tell if it's cleaning the html files. The command line argument added the following meta tags to all of the files:
<meta name="generator" content= "HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 15. +15), see www.w3.org">
I think my problem is currently with the config file. I looked on line and found something but I'm not sure if the content or format is correct. Here's my current config file:
output-xhtml: yes add-xml-decl: no doctype: strict char-encoding: ascii indent: auto wrap: 76 repeated-attributes: keep-last error-file: errs.txt
Do I even need to use the config file? I couldn't find a way to pass the arguments in the script. Any guidance and or help is greatly appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTML::Tidy help
by AnomalousMonk (Archbishop) on Feb 02, 2016 at 18:23 UTC | |
|
Re: HTML::Tidy help
by poj (Abbot) on Feb 02, 2016 at 19:06 UTC | |
by Anonymous Monk on Feb 02, 2016 at 21:46 UTC | |
by poj (Abbot) on Feb 02, 2016 at 21:54 UTC |