[ABE.pm] A coupla' more Qs

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Thu Oct 14 11:40:42 CDT 2004


* Faber Fedor <faber at linuxnj.com> [2004-10-13T23:02:50]
> 1.  I've got a bunch of separate programs that all share similar functions
> (connectToDB(), etc.).  I want to create a common library/file that all
> of these programs can include.  I tried "use" and "require" but the
> former expects a .pm and the latter doesn't scope the variables the way
> I want ($dbh in the include file is scoped only inside that file).
> 
> Do I need to learn how to write a Perl module or is there an easier way?

Look at the perldoc for "do", specifically "do EXPR"

This is ugly, and other programmers will probably scowl if they see it.
Writing a Perl module is /really/ easy, and a good thing to learn.

VERY VERY roughly, you could get away with this:

Assuming your code is in FaberCode.pm, you'd put that code in a
directory that's in @INC.  You'd put, at the beginning, "package
FaberCode;" and, at the end, "1;"

Now you can "use FaberCode;" and that package gets defined. If you have
a sub "foo" in it, you could call FaberCode::foo();  If you don't want
to prefix it with the name, you'd include lines like this, in
FaberCode.pm:

 @FaberCode::ISA = qw(Exporter);
 @FaberCode::EXPORT = qw(foo);

Consult perldoc perlmod, perldoc -f use, perldoc -f package, perldoc Exporter.

> 2. I HATE MAINFRAMERS AND THEIR FIXED-LENGTH RECORDS! (This ML isn't
> spidered by Google, is it? :-)  Does anyone have a good tool for
> determining where and how long fixed length records are?  I've been using
> the unpack() function and doing a trial and error (thank Ghu for
> ptkdb!).

I have no idea how you'd do that.

> 3. I need to separate things into a production database and a
> development database (running under one RDBMS).  I'm thinking of
> requiring a command-line argument; if --db=prodn is passed, the program
> reads/writes to the production database, otherwise, it R/Ws to the
> development DB.  Maybe I should make it an enviroment variable instead?
> Any suggestions on how to do this elegantly with my poor :-) Perl
> skills?

Both.
	$which_db = $opt{db} || $ENV{DB_FOR_FABER} || 'default';

> 4. Anyone use the ActiveState perl debugger?  Is it worth the money?  I
> use ptkdb when I need a GUI debugger, but I can't install that on the
> production server because A) it's a production server and B) the server
> is running RHEL3 and is a bit outdated.  I'm not too keen on losing
> up2date on the box, but I may go that route anywho.

I hate hate hate it... not because I use it, but because it makes it
basically impossible to use the wonderful standard Perl debugger.  I use
perldb all the time, and it rules.

-- 
rjbs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/archives/abe-pm/attachments/20041014/45d33ab6/attachment.bin


More information about the ABE-pm mailing list