On Wednesday, Sep 10, 2003, at 12:14 US/Pacific, Rodrigo Daniel de Lira wrote:
[..]

Can I to call a function that is in another script?

sorry interrupted. Allow me to illustrate a bit better


        /dir_for_cgi
                script1.cgi
                script2.cgi
        /lib/
                OurModule.pm

So we start the Module off with

        package OurModule
        VERSION = 1.01; # since you will have finished beta on it

        sub new
        {
       my $type  = shift;
       my $class = ref($type) || $type;
       my $self = {};
       bless $self, $class;

} # end of our simple new

        #
        # the subs go here
        #
    sub my_first_sub {
                my $me = shift; # to get the reference
                ...
    }
        .....
        1; # so that the use will see a happy return

Then each of the two cgi scripts can do the simpler

        use lib "../lib/;
        use OurModule;
        ...
        my $obj = new OurModule;
        ...

        my $first_thingie = $obj->my_first_sub(@arglist);
        ....

and one is out and away... No Mus, No Fuss.

Ok, so you COULD have done the Dilbert Class Solution of

        
        use lib "../lib/;
        use OurModule;
        ...
        my $first_thingie = OurModule->my_first_sub(@arglist);
        ...

Which ever makes you feel happier.

I would of course HIGHLY RECOMMEND that you get
Schwartz's "Learning Perl  Objects, References & Modules.
cf: <http://www.oreilly.com/catalog/lrnperlorm/>
for all the detail clarifications that are useful
above the standard

perldoc perlsub, perlmod, perlmodlib

The alternative to that is to have some funky interface
into the script with the function that will understand
that it is being called in some weird way that it should
pass the data to the function, and then return it out,
oh, say STDOUT. Trust me it can be done, but it is such
an ugly path that it should be left for the strictly
obfuscatory Perl Contest.

ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to