#!/usr/bin/perl use warnings; use strict; use IO::File; use File::Find; # # Valid HTML 4.01 Transitional find(\&fix_if_file,@ARGV); sub fix_if_file { return unless -f $_; my $fh = IO::File->new($_,'r') or die "Unable to open $_ for reading: $!"; local $/; my $fc = <$fh>; close($fh); # strip out the w3c img callback; replace with alt text my $changed = $fc =~ s{]*?alt="([^"]+)"[^>]*>}{$1}imsg; # if it doesn't have alt text, just replace it with Valid HTML $changed += $fc =~ s{]*>}{Valid HTML}imsg; if ($changed) { $fh = IO::File->new($_,'w') or die "Unable to open $_ for writing: $!"; print {$fh} $fc; close($fh); print STDERR "$File::Find::name was changed\n"; } }