Just looking at the rule checking, I can recommend putting the rules into a hash:
#!/usr/bin/perl -w
use strict;
# Define substitution rules using a hash. Note that these rules are
# stored in no particular order .. if this is very slow, efficiences
# can be achieved by changing to an array of hashes, with the most
# likely rule checked first.
my %Rules =
(
"p1" => "P1 = (inquiry, launch page)\n",
"p2" => "P2 = (car coverages, endorsements, operators)\n",
"p3" => "P3 = (notepad, scratch)\n",
"b1" => "B1 = (my inquiry: auto, home and location)",
"p0" => "P0 = (local search)\n",
"c0" => "C0 = (dist search)\n",
"c1" => "C1 = (state inquiry)\n",
"c3" => "C3 = (test notepad)\n",
"h1" => "H1 = (owners and coop search and history)\n"
);
# Process the input stream.
while ( <> )
{
foreach ( keys %Rules )
{
if ( m/iapw_$_/ )
{
s/iapw_$_/$Rules{ $_ }/ge;
print;
# Is there only one possible subsitution per line? If so,
# we could use a 'last' statement here to go on to the next
# line.
}
}
}
Your logic for opening up the log files is bizarre and does not compile on my system, but I'll presume that you have that part of the operation working correctly.
I can strongly recommend 'Learning Perl' from O'Reilly books. Read through that, try as many examples as you can, and you'll be far better off to tackle Perl projects.
--t. alex
"Mud, mud, glorious mud. Nothing quite like it for cooling the blood!" --Michael Flanders and Donald Swann
|