[Tallahassee-pm] Questions and such

Ryan Carmelo Briones mexnix at craonline.org
Tue Jul 1 09:52:07 CDT 2003


----- Original Message ----- 
From: "Rebekah Landbeck" <rlandbeck at uniteddatatronics.com>
To: <tallahassee-pm at mail.pm.org>
Sent: Tuesday, July 01, 2003 10:30 AM
Subject: [Tallahassee-pm] Questions and such


>
> Ok, here goes with the background info before I get to the questions:
>
> Whoever wrote this app wrote each CGI script as if it were the only one in
> the whole thing.  Code is duplicated all over the place, particularly
> database connection stuff.  I need to consolidate all the database code
> into a package because the connection info varies.
>
> The CGI scripts are called in the middle of html pages.  All they do (at
> least, the ones I'm dealing with just now) is pull a list of names from
the
> database and format them for the html.  I've got the pages using an
> included config file to decide what code to use to run the cgi scripts,
> depending on physical location.  That gruesome hack I referred to comes
> into play here.  PHP uses a regex on the working directory to figure out
> whether it's on the development box (Win2k, how's that for ugly... making
> these things work cross-platform sure is teaching me a lot, though), in
the
> test directory on the live server, or in the live directory, and writes a
> string to whereami.txt indicating where it is.
>
> When a CGI script is called, it reads from whereami.txt and sets the
> database connection info accordingly.  That's what I need to put into a
> package.  As a quick fix to get the feature I'm adding right now working,
I
> could rewrite those couple of scripts in PHP, but before long I'll need
> that package anyway to make the rest of the site portable between test and
> live versions.
>
> ... I hope that made sense.  :o)
>
> Questions concerning Exporter:
>
> 1)  Is using Exporter necessary/the best way to include a seperate package
> file?
only if you're importing functions or variables into the main namespace.
otherwise, no need for exporter. you could always use Object-Oriented
programming and create a class would probably make it a lot easier...

>
> 2)  The PHP include() reads the file into the current one as if the code
> were written in the current file.  I haven't come across anything that I
> can recall in PHP regarding namespaces, but I have an ok grasp of the
> concept.  I think.  The Exporter doc says "use ModuleName; This imports
all
> the symbols from ModuleName's @EXPORT into the namespace of the use
> statement." Does that essentially mean the same thing?
no, if you want to do the same as PHP's include(), you'll want Perl's
require() or do(). in this case you wouldn't use "use Module;" if you use
Exporter and @EXPORT you'd have to specify every function you wanted import
into main.

>
> 3)  I read that exporting method names isn't good.  Is that why you would
> use Modulename();, importing no symbols?
"use Modulename;" is normally used for OO packages. Perl programmers are
really anal. it's not REALLY bad to export THINGIES into the main namespace,
it's just "bad form" according to the Perl wizards. you can do whatever you
want according to your needs, it's not going to hurt perl's feelings, but if
you decide to release any of this to CPAN, then you might consider using
Exporter and @EXPORT_OK per the documentation

>
> 4)  It seems that 'symbols' refers to references to variable names or to
> sub names.  Is that right?
basically, yes. i think you'd do really good reading Programming Perl,
Advanced Perl Programming, and Object-Oriented Perl. APP is very outdated,
but when i read it, it really opened my eyes on how Perl internals worked.
OOP is the object-oriented perl programmers bible. everything you ever
wanted to know about packages, namespaces, and OOP.


>
> Thanks in advance...
>
> Rebekah

on a side note, i think you should really look into the best ways you can
use the CPAN. there are loads and loads of modules there to make your job a
lot easier. i don't know what you're using now, but when you run into one
task that looks like it's going to take more than a page of code, you should
really look towards the CPAN. have fun.

ryan briones




More information about the Tallahassee-pm mailing list