I'm very new with PERL and have been given a task of doing some maint.
on an existing really big PERL program. What I'd like to ask is if the
changes
I want to implement will work and ask for suggestions on how to make one
major change working with subroutines.
The application makes use of a number of arrays that contain categories
and subcategories. What I'd like to do is to move these into a separate
file (extras.pl) and reference it with a "require". These structures
were
in the mainline program. Adding new categories involved editing the
mainline code, so my thought was it would be easier and less trouble-
prone to put them in a separate file to which new ones could be added
easily. What I want to add to the external "required" file are these
objects. Can I do this pretty transparently and easily? Will I run into
any
serious problems by moving them to a separate file?
------------------------------------------------------------------------
----------------
use vars qw(%config %category %paper %records);
%category = (
p01 => 'PAPER ITEMS GENERAL',
p02 => 'Diaries and Journals',
p03 => 'Indentures',
p04 => 'Letters',
p05 => 'Certificates',
p10 => 'Other Paper Items',
r01 => 'RECORDS GENERAL',
r02 => 'Birth and Death',
r03 => 'Marriage ',
r04 => 'Wills ',
r05 => 'Census',
r06 => 'Court and Probate',
r07 => 'Immigration and Ship Lists',
r08 => 'Military',
r09 => 'Maps',
r10 => 'Other Records',
);
%paper = (
p01 => 'PAPER ITEMS GENERAL',
p02 => 'Diaries and Journals',
p03 => 'Indentures',
p04 => 'Letters',
p05 => 'Certificates',
p10 => 'Other Paper Items',
);
%records = (
r01 => 'RECORDS GENERAL',
r02 => 'Birth and Death',
r03 => 'Marriage ',
r04 => 'Wills ',
r05 => 'Census',
r06 => 'Court and Probate',
r07 => 'Immigration and Ship Lists',
r08 => 'Military',
r09 => 'Maps',
r10 => 'Other Records',
);
------------------------------------------------------------------------
----------
Secondly, when additional categories are added, the program is coded
such
that a new subroutine has to be inserted dealing with that category. For
example,
there would be a subroutine added for "paper" and one for "records". In
each
subroutine there are only 3 "references" to the item. For example, in
the "paper"
subroutine there are only these 3 places where "paper stuff" is
mentioned. Sample
is below (with non-relevant code removed). So, if we had 10 categories
there
would be ten subroutines - one for each category - differing only in the
3 places
where the category topic is mentioned. My question - is it possible to
create only
one "generic" subroutine that could have the topic name plugged in
rather than
having ten almost-alike subroutines? If so, can you recommend a sample
code
snippet that I can model the procedure after?
These subroutines are accessed by :
elsif ($form{'action'} eq 'paper') { &paper; } #Paper Items Category
elsif ($form{'action'} eq 'records') { &records; } #Records Category
sub paper {
&chkclose;
print "<p align=center><b><font color=$config{'colortablebody'}
face=Arial size=2>Paper Categories</font></b></td></tr>";
my $key;
foreach $key (sort keys %paper) {
}}
sub records {
&chkclose;
print "<p align=center><b><font color=$config{'colortablebody'}
face=Arial size=2>Records Categories</font></b></td></tr>";
my $key;
foreach $key (sort keys %records) {
}}
Thanks for your suggestions, ideas, comments, etc.
Portions of this message may be confidential under an exemption to Ohio's
public records law or under a legal privilege. If you have received this
message in error or due to an unauthorized transmission or interception, please
delete all copies from your system without disclosing, copying, or transmitting
this message.