#!/usr/bin/perl -w #program to find img tags w/o alt attributes use strict; use HTML::TokeParser; #build list of HTML files in the same directoy my @files=<*>; @files = grep(/[.]htm/i ,@files); #parse each file for my $file (@files) { my $p = HTML::TokeParser->new( $file ); #move through each html token in the file while (my $token = $p->get_token){ #find IMG start tags if ($token->[0] eq "S" && $token->[1] =~ /img/i) { my $alt_count = 0; for my $token (keys %{$token->[2]}){ #if alt tag is found count it ++$alt_count if $token =~ /alt/i; } if ($alt_count < 1){ #if we get here print a message and jump to the next file print "$file is missing an alt attribute in an img tag\n"; last; } } } }