Testing the Script Again

The current version of make_exhibit.plx , with all the sanity checks and category-parsing code added, is given in Example 5-4.

Example 5-4. Updated version of make_exhibit.plx

#!/usr/bin/perl -w # make_exhibit.plx # this script reads a pair of data files, extracts information # relating to a group of tradeshow exhibitors, and writes # out a browseable web-based directory of those exhibitors use strict; # configuration section: my $exhibit_file = './exhibit.txt'; my $category_file = './category.txt'; # script-wide variables: my %listing; # key: company name ($co_name). # value: HTML-ized listing for this company. my %companies_by_category; # key: category name. # value: $co_name\n$co_name\n$co_name... # read and parse the main exhibitor file my @listing_lines = ( ); # holds current listing's lines for passing # to the &parse_exhibitor subroutine open EXHIBIT, $exhibit_file or die "Can't open $exhibit_file for reading: $!\n"; while (<EXHIBIT>) { if (/^\s*$/) { # this line is blank (or has nothing but space chars) if (@listing_lines) { &parse_exhibitor(@listing_lines); @listing_lines = ( ); } } else { # this line actually has data push @listing_lines, $_; } } # process last batch of lines, if the file didn't have a trailing # blank line to trigger it already. if (@listing_lines) { &parse_exhibitor(@listing_lines); } close EXHIBIT or die "Can't close $exhibit_file after reading: $!\n"; # read and parse the category file my @category_lines = ( ); # holds current ...

Get Perl for Web Site Management now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.