Please modify the above program, so it replaces all the images (e.g. .jpg or .gif images) inside any page with a picture of your choice. When an HTML web page contains images, the browser will identify those image URLs, and send out an URL request for each image. You should be able to see the URLs in your URL rewriting program. You just need to decide whether a URL is trying to fetch an image file of a particular type; if it is, you can replace the URL with another one (of your choice).
use strict;
use warnings;
# Forces a flush after every write or print on the STDOUT
select STDOUT; $| = 1;
# Get the input line by line from the standard input.
# Each line contains an URL and some other information.
while (<>)
{
my @parts = split;
my $url = $parts[0];
# If you copy and paste this code from this PDF file,
# the ˜ (tilde) character may not be copied correctly.
# Remove it, and then type the character manually.
if ($url =˜ /www\.cis\.syr\.edu/) {
# URL Rewriting
print "http://www.yahoo.com\n";
}
else {
# No Rewriting.
print "\n";
}
}