[ABE.pm] Fwd: A better way?

Faber Fedor faber at linuxnj.com
Fri Oct 13 06:04:34 PDT 2006


---------- Forwarded message ----------
From: Faber Fedor <faber at linuxnj.com>
Date: Oct 12, 2006 10:04 PM
Subject: Re: [ABE.pm] A better way?
To: Ricardo SIGNES <rjbs-perl-abe at lists.manxome.org>


On 10/12/06, Ricardo SIGNES <rjbs-perl-abe at lists.manxome.org> wrote:
> * "Faber J. Fedor" <faber at linuxnj.com> [2006-10-12T20:25:14]
> > Is there a more elegant way to do this?
>
> Well, I'm not exactly sure, but I think this will do what you want:
>
>   for my $i (0 .. $end) {
>       if ( !defined($captArray[$i])) {
>           generateException($cusipArray[$i]);
>           next;
>       }
>       # do some useful stuff here
>   }
>
>   print_exception_report;
>
>   {
>       my @ListOfCusips;
>
>       sub generateException {
>           ($cusip) = @_;
>           push @ListOfCusips, $cusip;
>       }
>
>       sub print_exception_report {
>           magically_print_the_array_to_file(@ListOfCusips);
>       }
>   }
>
> I'm not really sure what the point of all this is, though.

I hadn't thought to put both functions inside the block.  DOH!

> Why not this:
>
>   my @ListOfCusips;

My for loop is actually inside of another function and not the main()
of the program. Also, as a rule of thumb I try to avoid global
variables (even though I've got plenty!)

> Also, the fact that you have two arrays with parallel indices really makes it
> look like you want a hash.

I *knew* someone was going to mention that!  I didn't write this code
but it's so crucial to the day-to-day operations and is quite complex
that rewriting it would be quite painful. Besides my to-do list is
already overwhelming. Instead of executing a bunch of SQL in the
database, the guy pulled the data down into individual two-column
objects and joined them using Data::Table.  So not only is the program
doing work in Perl that should be done in the database, I've got six
or seven objects that are essentially just arrays (some thousands of
elements long) that have to stay in sync.

You don't even want to know how this guy decided to write out 15 files
consisting of two columns where only the data in the second column
changes!


--

Regards,

Faber Fedor
Linux New Jersey, Inc.
908-320-0357
http://www.linuxnj.com


-- 

Regards,

Faber Fedor
Linux New Jersey, Inc.
908-320-0357
http://www.linuxnj.com


More information about the ABE-pm mailing list