> Hi, I'm starting to look at OO in PERL, I've written a working class
but I
> don't know how to implement private and public variables and accessor
> functions, any idea how to do that?
>
'Perl' or 'perl' never PERL.
perldoc perlboot
perldoc perltoot
perldoc perltooc
perldoc perlbot
Lots of help in the above, and probably better answers to your questions
since they are pretty general.
> Here's wot I have so far:
> ###############################################
> #!/usr/bin/perl -w
>
> use strict;
> use CGI;
> my $q = new CGI;
>
> my $count = 0;
>
> # this class takes no constructor parameters
> package TRACKER::GraemeTestClass;
> sub new{
> my $classname = shift; # we know our class name
> $count++; # remember how many objects
> bless {}, $classname; # and bless an anonymous hash
> }
> sub count{
> my $self = shift; # this is the object itself
Actually this looks more like a class method, so "object itself" is a
little unclear. $self is probably the Class rather than an instance
(though in this case it doesn't matter, isn't Perl grand :-))
> return $count;
> }
>
> sub GetNameFromForm{
> my $self = shift;
> $self->{name}=$q->param("name");
> }
>
> sub PrintName{
> my $self=shift;
> return $self->{name};
> }
>
This looks like an accessor to me, are you having a problem?
>
> Cheers in advance for any tips,
>
Are you having a problem in particular? Do you need private/public
variable distinction, etc.? Unless you have something specific I would
start going through the docs mentioned above, additionally if you are a
book person, Learning Perl Objects, References, and Modules (Schwartz
and Phoenix, O'Reilly) is excellent as is the slightly dated Object
Oriented Perl (Conway, Manning).
Good luck,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>