CSCI 4230
 Internet Application Development
 Summer 2001
 Homework #2

Due date:

(1)    Write a Perl program imageLinkExtractor.pl to take three command line arguments: url, dir and the title of the image collections.

The program extracts and saves the images within the specified url into the directory dir and generates an image descriptin file in the directory.  The images are saved using the file names of their url.  Only the images specified by the <img> tags are saved.  Furthermore, the images should not have an alt attribute value that ends with .jpg, .jpeg or .gif.

The image description file stores the description of one image per line in the format of

filename::description

The description is the alt attribute value.

The first line of the image description file is the title of the image collection.  The title is obtained from the third command line argument.

The program creates the subdirectory dir in the current directory and generates an error message if the directory already exists.

For example, executing:

F:>ImageLinkExtractor.pl http://scarlett745836.tripod.com/scarlett745836/id5.html gwtw "Gone with the wind"

prints the following to stdout:

The URL http://scarlett745836.tripod.com/scarlett745836/id5.html has been succesully processed.
65 images are added to the directory gwtw.
Image description file is image_desc.txt

The file content of image_desc.txt:

Gone with the wind
sadpc.jpg::scarlett looking at ashley and melly
shimmy.jpg::scarlett and cathleen walking up the stairs
rhetscar.jpg::the atlanta escape
neverhungry.jpg::never hungry again
bonniescarlett.jpg::bonnie and scarlett
scarlettanddad.jpg::scarlett and gerald walking at tara
bbqdrs01.jpg::fiddle dee dee
pittypat.jpg::christmas leave
gwtw12.gif::scarlett and rhett in bedroom
happy.jpg::scarlett waiting for rhett
cukorvivselzhowhav.jpg::cast signing contracts
rhett4-r&belle.jpg::rhett and belle watling
gwtw18.gif::the first cocver for the book
rhetsca.jpg::clark and vivien publicity shot
afterbonnie.jpg::scarlett after bonnie was born
dscar.jpg::scarlett drinking after franks death
scarlett19-s&ashleybbq.jpg::the slap in the library
pascar.gif::scarlett and pa on the lawn of tara
greendress.jpg::greendress shadows
1gwtw05.gif::belle and melly
myfaveposter2.jpg::original gwtw poster
whitedress.gif::scarlett running to wait for pa
3_copyl.jpg::scarlett talking to her pa
scarlettandashley.jpg::scarlett and ashlet at mellie's death
leighpc.jpg::scarlett in muslin dress portrait
scarhet3.jpg::scarlett with her green bonnet from paris
vivlh7.jpg::scarlett and ashley in a scene that was deleted
scarlettwrhett.jpg::scarlett with rhett
gwtw21.gif::new book cover
scarmelmam.jpg::melly and mammy after bonnie is born
mellyscarlett.jpg::the birth of beau
fire.jpg::rhett and scarlett and the first kiss
stairsgt.gif::scarlett looking at the girls on the stairs
ashleyscarlett.jpg::scarlett and ashley
cryingscarlett.jpg::scarlett as a widow crying
scarrhett.jpg::scarlett and rhett in a deleted scene
scxarrhettfood.jpg::scarlett and rhett eating
1gwtw12.gif::scarlett and mely at her death
tomthecop.jpg::shanty town night
scarletturn.jpg::scarlett smiling picture
dreamscene.jpg::scarlett and rhett in the dream scene
flemingviv.jpg::fleming and vivien on the set
sunset.gif::scarlett and pa in sunset
kiss.jpg::the proposal
scarlett10-draperydress3.jpg::scarlett and mammy and the portiers
cryingviv.jpg::Scarlett crying
whitedress.jpg::scarlett bored
gwtw71.gif::portrait of scarlett
gwtw74.gif::the stairs scene
filmcover1960pc.jpg::famous gwtwt poster
bbqdresstill.jpg::bbq dress still
thefirstpicofgreendress.jpg::scarlett and tarleton twins at tara
reddresspc.jpg::scarlett in red dress
bluegfwt.gif::scarlett getting ready for the bbq
scarletthospitalescape.jpg::scarlett hospital escape set
scarlett14-mornafterstairs.jpg::scarlett the morning after the stairs scene
4_copyl.jpg::scarlett praying
lockdoor.jpg::no more babies
scarhett.jpg::scarlett and rhett at tara
selz.jpg::selznick with scarlett portrait
rhettmellie.jpg::rhett crying
mewlscarl.gif::melly and scarlett in atlanta
1gwtw7.gif::scarlett still picture
bazaar.gif::the bazaar in atlanta
handkisspc.jpg::scarlett and rhett on honeymoon

The directory contents of gwtw:

Turn in:

(A)    Source code
(B)    A listing of the image description file using the test case above.
(C)    A disk containing the source code and the test run.
(D)    Create a top level directory "hw" under your account (not under the subdirectory pages).  Create "h3" under "hw". Put all programs into hw/h3.  The T.A. will access your account to test run your program.

(2)    Write a Perl function mergeHash to merge two hashes.  The references of the two hashes are passed as arguments.  The function returns a hash that merges the two input hashes.  If a key appears in both input hashes, then the value of the key of the output hash is a reference to an anonymous array containing the two key values.

For example, executing the code:

use strict;
my %a = (dog => 123,
   cat => 135,
   rat => 100,
   mice => 95);
my %b = (mice => 'not nice',
   dog => 'nice',
   tiger => 'oh, oh');

my %result = mergeHash(\%a, \%b);

set %result to:

(dog => [123, 'nice'],
 cat => 135,
 rat => 100,
 mice => [95, 'not nice'],
 tiger => 'oh, oh')

(3)    Write the Perl code to print %result (or any hash that contains either numbers, strings and reference to anonymous arrays of numbers and strings as elements) in the following format:

cat => 135
dog => 123  nice
mice => 95  not nice
rat => 100
tiger => oh, oh