Well I use the AUTOLOAD when Such a thing is required

write a single function

sub AUTOLOAD {
my $self = shift;
my ($parameter)=shift;
my ($value)=shift;
$self->{$parameter} = $value if($value);

return $self->{$parameter};

}

Now U can use $obj->CNAME("ABC");


But we warned that using AUTOLOAD can give a lot of debugging pain especially when U misspell any valid function name






Nicole Seitz wrote:
Hi there!

I've just started to learn OOP with Perl.With the help of perltoot I wrote a class Person and some methods(see below).

package Person;
use strict;

sub new {
my $self = {};
my $proto = shift;
my $class = ref($proto) || $proto;
$self->{CNAME} = undef;
$self->{SNAME} = undef;
$self->{STREET} = undef;
$self->{CITY} = undef;
$self->{PHONE} = undef;
$self->{EMAIL} = undef;

bless ($self, $class);
return $self;

}

sub cname {
my $self = shift;
if (@_) {$self->{CNAME} = shift }
return $self->{CNAME};
}

sub sname {
my $self = shift;
if (@_) {$self->{SNAME} = shift }
return $self->{SNAME};
}

sub street {
my $self = shift;
if (@_) {$self->{STREET} = shift }
return $self->{STREET};
}

sub city {
my $self = shift;
if (@_) {$self->{CITY} = shift }
return $self->{CITY};
}
sub phone {
my $self = shift;
if (@_) {$self->{PHONE} = shift }
return $self->{PHONE};
}

To store some data in my object I did the follwing:

use Person;

$myPerson = Person->new();
$myPerson->cname("John");
$myPerson->sname("Smith");
$myPerson->street("Euston Road");
$myPerson->city("London");
$myPerson->phone("414 3344");


Do I really need all these methods?
I get my data from an comma separated file;lines in this file look like this:
;John;Smith;Euston Road;London;414 3344;;

So, after opening the file and reading from it line per line,
what's the best way to store the data in an object? Can I do it in one step?I mean, without using several methods(cname,sname,...)???

Many thanx in advance!

Nicole






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

Reply via email to