Library Catalog Search

This part of the assignment involves building a simple search engine in Perl to search a library catalog. Call the script catalog.plx.

The script will obtain queries from a query file called query.input. A single query stored in the query file has the following format:

The above items are each on their own lines in the file. Some example queries:
1 # find books with perl OR cgi as subjects
perl cgi
SUBJECT
OR
EXACT
2 # find by author: use last or first or last,first to specify
Cormen Susan Rivest,Ronald
AUTHOR
AND
EXACT
3 # find titles with data AND structures as substrings
data structures
TITLE
AND
SUBSTRING

Once the five lines comprising a single query are read, the query tag should be written out on a line by itself to a query output file, call it query.output. The search strings should also be separated and stored in their own array. They will be used to create one or more regular expressions that will be employed to search through a database file named catalog.dat based on the commands read from the query file.

The format of a line in the database file is as follows:

An example line of the database file:

Schwartz,Randal;Christiansen,Tom|Learning Perl|perl cgi programming|due 98-04-22


The query commands should be handled as follows (all searches should be case insensitive):

For each query, the engine should search through the entire database file. If a search performed on a target yields a hit, a line of the following form should be written out to the query output file along with a newline:

<author list>|<title>|<status>
For example, query 1 above would produce the following line in query.output:
Schwartz,Randal;Christiansen,Tom|Learning Perl|due 98-04-22
Once the entire database file has been searched and all hits have been written out to the query output file, a new query should be read from the query file and the process should be repeated until the query file is exhausted.

Example query.input, catalog.dat, and query.output files will be made available on the class webpage.


up previous
Up: Project 1 Previous: Regex for Floats

Moorthy
5/28/1998