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:
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:
|
),
followed by a title, followed by a vertical bar, followed by a list
of subjects that the book has information on, followed by a vertical
bar, followed by the book status. A line ends with a newline.
available
or due <date>
where date is the day the book is due back given as
<last-two-digits of year>-<two-digit-month>-<two-digit-day>
.
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):
lastname,firstname
(i.e., you may search for it as a
single string). The TITLE command means that the search should
occur on the title portion of each line in the database, and the
SUBJECT command indicates the search should be done on the list of
subjects. Note that this command simply directs the target of the
search; the search itself is no different in each case.
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-22Once 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.