use strict; use vars qw/%PhoneBook/; # Read in CSV phone book ReadPhoneBookFile(); # Run two parameter tests my $ValidTest = "8594"; my $InvalidTest = "9999"; print "Parameter test 1 - Number to find is: $ValidTest\n"; print 'The caller was: ', MatchPhoneNumber($ValidTest), "\n"; print "\nParameter test 2 - Number to find is: $InvalidTest\n"; print 'The caller was: ', MatchPhoneNumber($InvalidTest), "\n"; exit; sub ReadPhoneBookFile ### ### Reads in a CSV separated phone book, splits, stuffs details into a hash ### ### In real-world script, data is read from an external file. { foreach () { my @Details = split(/,/,$_); $PhoneBook{$Details[0]} = $Details[1]; } } sub MatchPhoneNumber ### ### Attempts to match the phone number with a name from the phonebook ### Either returns the caller name if number in hash or "Unknown caller". ### { my $NumToFind = shift; return defined $PhoneBook{$NumToFind} ? $PhoneBook{$NumToFind} : 'Unknown Caller'; } __DATA__ 8594,Tom 9000,Dick 1234,Harry