[NCLUG] newbie perl question...

S. Luke Jones luke at frii.com
Thu Aug 16 22:09:07 MDT 2001


Let me explain. No. Is too complicated. Let me sum up.

I am writing some scripts in Perl and I'd like to reuse a couple
of functions I've written. Is there an EASY way to do this, or
do I have to figure out packages and blessed references and crap
like that?

Oh, heck, let me explain after all:

There's this database that I can't query myself but instead I have
to use a predefined report. I'm using Excel's Pivot Tables for most
of what I need to do, but before I get there I need to clean up the
data (as provided in the report) a bit. I'm using Perl for this
purpose, which is approximately why Larry originally invented it.

There are a couple of steps in my post-processing workflow.
(I should probably use Perl to automate those as well, since I'm
on a system without a useful shell language or even make, but
put that to one side for a minute.) There are a couple of things
I want to do at each step in the workflow, e.g.

	print join "\t", @fields;

but it's really

	if( not header_printed ) {
		header_printed = 1;
		# ah! this is header data. keep it so Excel will be
		# happy but turn it into a comment so it won't get
		# in the way of downstream processing.
		$fields[0] = "# $fields[0]";
	}
	print join "\t", @fields;

I'm working with over one hundred columns of data, when they're all
there, which they -- all too often -- aren't, so I also have a flag
that will cause every field in a record to be prepended with a column
number so I can easily tell what went wrong where.

And so forth. By now my simple "print join tab" logic is about 25
lines long. I'm sure that a JAPH could convert it to 83 characters
randomly selected from the top row of the keyboard, but even then my
question would remain: is there a simple way to reuse that logic in
all my scripts?

All I want is something like the shell's "source" a/k/a "." command.
Maybe this is false laziness. Maybe what I really need to do is write
this up as an honest-to-goodness module and submit it to CPAN module
to help out the next poor bastard  Maybe if I ever manage to make it
through "man perlmod" and "man perlmodlib" and so forth I'll do that.

In the meantime, is there an easy way to do this that I've missed?

-- 
Luke Jones = luke/vortex/frii/fullstop/com



More information about the NCLUG mailing list