[tpm] Perl module question
Richard Dice
rdice at pobox.com
Fri Sep 7 11:43:08 PDT 2007
Shaun,
> 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);
Yes, certainly. I only alluded to it in my email, when I talked about
procedural vs. object oriented Perl module programming. I avoided going
into these details on it because they actually come out when you read the
perlboot link that I sent.
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.
Unless you start getting into importer/exporter stuff. But that, as they
say, is another story. :-)
Cheers,
Richard
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)=@_;
> > ...
> > }
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/toronto-pm/attachments/20070907/9ee987d6/attachment-0001.html
More information about the toronto-pm
mailing list