#!/usr/bin/env perl
#Adds trivial "alt=pix" tag to
, in order to
#satisfy "Bobby compliance". http://www.cast.org/bobby/
#example usage: bobby.pl *.html
for $file (@ARGV){ # @ARGV contains *.html glob
print "$file\n"; #print name of file being modified
open INFILE,"<$file";
@all=; #put the lines of the file into an array
close INFILE;
open OUTFILE,">$file"; #reopen file for writing
for $line (@all){
#Note the three groupings in ( ) in the first match search.
#Not only match "
)/) && ($2!~m/alt=/) ){
print $line; #print line before modification
#~s means substitute 2nd / / for first / /. Note use of $1 and $2,
#which back references to the ( ) and ( ) in the first / /.
$line=~s/(<\s*img\s+src=.*?)(>)/$1 alt="pix"$2/;
print $line,"\n"; #print line after modification, and skip a line.
}
print OUTFILE $line; #print line, modified or not, out to file
}
close OUTFILE;
}