[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] "What's the best way to..."



First off, let me say I really enjoy this list -- I've learned a lot, about
Perl and programming in general since I first started subscribing to it.

On to my question.

My first MacPerl program was a drag-n-drop program that takes a file from
our proprietary mainframe system in a 'garbled' format and sorts it into a
tab deliminated text file that is structured like this:

Ad_Number     Ad_Classification_Number      Ad_Text

The first two fields are numbers, and the last one is a huge text string.
This next goes onto our WWW server, and viola! you've got
http://www.news-gazette.com/classifieds/

Everything's been working excellent, but now it's time to improve... so I
thought I might enlist some list design help _before_ I start coding.  What
I need to do is to create two new fields based on the Ad_Classification
number -- Major_Classification and Minor_Classification.  Essentially what
I want to do in  psudeo-code is:

   If Ad_Classification > 100 and < 200 then Major Classification =
Announcements

   That's the easy part.

   Next, our advertising department has the ads broken down so
classification 102 is General Announcements, 103 is 'Card of Thanks,' etc,
all the way up to 817 'Automobiles'.  They also like to be able to
restructure the classification system on short notice, so I'd like to store
the table of data in a separate, human-readable and easily edited format...
something like:

100     Legal Services
101     Announcements
102     Political Announcements

....

817     Automobiles


I'm not looking for someone to write the code, I'm just looking for some
general pointers on the most efficient strategy to take given the
limitations.  I'm currently thinking of reading a tab-delimited file in and
making it an associative array like:


$_ = FILE;

@table_of_values = split;                  # split on the default
                                           # whitespace -- does
                                           # this include \n?

$arraytable = join("\",\"", @table_of_values);
$arraytable = "\"$arraytable\"";           # wrap quotes around the
                                           # whole thing so we can use
                                           # it to build an assoc.
                                           # array


%MinorClassificationTable = ($arraytable); # build the assoc. array

foreach(ad) {

  $Minor_Classification =
              $MinorClassificationTable($Ad_Classification_Number);

                                           # Use the classification
                                           # number to find the string



How's sound is this in terms of Perl effecincy?  It's taking about 5-10
seconds to run the current script, and I don't want to add a whole lot more
time.

Matt

childress@news-gazette.com
http://www.news-gazette.com/