Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the following command line in terminal on a Mac to clean over 500 html files in the folder Test: find /Users/joe/desktop/01282016/Test -type f -name "*.html" -exec tidy -f errors.txt -m -utf8 -i {} \; How can I do this with a perl script? I've checked CPAN but the documentation for this module is very brief and didn't help. Any help is greatly appreciated

Replies are listed 'Best First'.
Re: Perl HTML::Tidy
by FreeBeerReekingMonk (Deacon) on Feb 01, 2016 at 19:04 UTC
Re: Perl HTML::Tidy
by GotToBTru (Prior) on Feb 01, 2016 at 19:23 UTC

    What do you have so far?

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      Thanks for pointing me at the additional documentation. I just installed Alien::TidyP and HTML::Today and have the following non working code. It's not grabbing any files yet. I'll continue to work on it:

      use HTML::Tidy; my $call_dir = "/Users/joe/desktop/Test8"; #my $tidy = HTML::Tidy->new( {config_file => 'path/to/config'} ); my @files = glob "$calls_dir/*.hmtl"; printf "Got %d files\n", scalar @files; for my $file (@files) { open my $in_fh, '<', $file; $tidy->ignore( type => TIDY_WARNING, type => TIDY_INFO ); $tidy->parse( $file, $contents_of_file ); for my $message ( $tidy->messages ) { print $message->as_string; } }

        You have a couple of typos - have a look at Use strict and warnings

        my @files = glob "$calls_dir/*.hmtl"; # should be $call_dir and 'html'

        I don't think this does what you think

        $tidy->parse( $file, $contents_of_file )

        From the docs :

        parse( $filename, $str [, $str...] ) Parses a string, or list of strings, that make up a single HTML file. The $filename parm is only used as an identifier for your use. The file is not actually read and opened.

        Try instead

        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 ) or warn "Error parsing $file :$!";
        poj