[tpm] Perl module question

Shaun Fryer sfryer at sourcery.ca
Fri Sep 7 11:08:15 PDT 2007


Hi Madison,

Richard already answered your question in the main, but here's
a quick work around for you. If you don't need the robustness
of object oriented programming, you can skip the step of building
an instance via a construcor (new()) and simply substitute the
pointer arrow (->) with colons (::). So for instance...

my $result_0 = Your::Procedural::function_0($var1, $var2);
my $result_1 = Your::Procedural::function_1($result_0);

The only caveat is that you will have to state the full module
name as part of the function call each time, just as above. This
will get around having to shift off the package name, or blessed
instance as the case may be.

That said however, it's very much worthwhile to learn object
oriented programming methodology and techniques. In the long run
this will make your code (especially larger applications) *much*
more maintainable and extensible. Understanding object
"inheritance" especially is extremely valuable, although I would
caution you to learn what "multiple inheritance" is, and both
why and how to avoid it.

Good luck and happy reading. :)
--
    Shaun Fryer

On Fri, Sep 07, 2007 at 12:20:29PM -0400, Madison Kelly wrote:
> Hi all,
> 
>    I am quite the module n00b, so please be gentle. :)
> 
>    I've got a few small, simple modules I've written that handle some 
> simple functions I use often. What I want to be able to do though is:
> 
> my $foo=My::Module->new();
> 
>    Then be able to call the function/subroutines in there like this:
> 
> my $value=$foo->function($var1, $var2);
> 
>    I had tried to do:
> 
> my $value=My::Module->function($var1, $var2);
> 
>    But the first value picked up in the function is the module name... I 
> don't think I should have to say in the module
> 
> sub function
> {
> 	my ($null, $var1, $var2)=@_;
> 	...
> }


More information about the toronto-pm mailing list