It did complain or else I would have sent a thank you for making it work
already ;)

> James pretty much covered everything, but here are my two coppers.
>
> First thing is that this line is wrong...
>
>> my $self = { fname, lname };
>
> It should be this...
>
> my $self = {fname => '', lname => ''};
>
> If you had use strict or warnings on it would have yelled about that one.
> The way you had it, it was setting "fname" to "lname" instead of creating
> two different fields.
>
>>> use UserInfo;
>>
>> Okay, UserInfo is better, but doesn't tell
>> us much.  I was thinking something more like
>> ComputerUser, DatabaseUser, GymUser, etc.
>
> I actually like "UserInfo", it means you can make "ComputerUser" and
> "GymUser" subclasses :)  ...but I would hold off on that until everything
> else sinks in.
>
> Rob
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, September 30, 2003 7:53 PM
> To: James Edward Gray II
> Cc: [EMAIL PROTECTED]
> Subject: Re: Look At This Package
>
>
> James and Rob,
>
> OK version x.2
> - I want to create a user object with value initialized.
> - Initialize/Change it anytime
>
> test.pl
> -------
> use UserInfo;
>
> my $ui = new UserInfo();
> $ui->(fname) = "bob";
> $ui->(lname) = "Bingham";
>
> #change name
> $ui->(fname) = "robert";
>
> print "ui: [" . $ui->full_name() . "]\n";
>
> exit
>
> UserInfo.pm
> -----------
> #!/usr/bin/perl
> package UserInfo;
>
> sub new
> { my $class = shift;
>   my $self = { fname, lname };
>   return bless $self, $class;
> }
>
> sub full_name
> { my $self = shift;
>   return $self->{fname} . ' ' . $self->{lname};
> }
>
> 1;
>
>>
>> On Tuesday, September 30, 2003, at 06:01  PM, [EMAIL PROTECTED] wrote:
>>
>>> Can someone make this work like I want? I'm trying to create a package
>>> USER and reference/change it. The only thing I'm able to do is to call
>>> the
>>> sub prtAll. I just want a structure that I can pass around in perl.
>>>
>>> test.pl
>>> -------
>>
>> Good code starts with the following, I promise.
>>
>> use strict;
>> use warnings;
>>
>>> use USER;
>>
>> Let's drop the all caps here.  Perl tradition is class names in
>> titlecase.  The name could also be more descriptive.  What kind of user?
>>
>> use User;
>>
>>> #this does NOT work
>>> #how do i reference these vars
>>> USER::fname="bob";
>>> USER::lname="Bingham";
>>
>> It doesn't work because you forgot the special variable symbols.
>>
>> $User::fname = 'bob';
>> $User::lname = 'Bingham';
>>
>> However, objects would probably be better here, so let's try:
>>
>> my $user = User->new(f_name => 'bob', l_name => 'Bingham');
>>
>>> print USER::prt . "\n";
>>
>> print $user->full_name(), "\n";
>>
>>> USER.pm
>>
>> User.pm
>>
>>> -------
>>> package USER;
>>
>> package User;
>>
>> use strict;
>> use warnings;
>>
>>> $fname;
>>> $lname;
>>
>> These would need to use our(), under strict:
>>
>> our($fname, $lname);
>>
>> But we don't need them.
>>
>> sub new {
>>      my $class = shift;
>>      my $self = { f_name => 'John', l_name => 'Doe', @_ };
>>      return bless $self, $class;
>> }
>>
>> sub full_name {
>>      my $self = shift;
>>      return $self->{f_name} . ' ' . $self->{l_name};
>> }
>>
>> That's very basic object oriented programming, tell me if you need
>> parts of it explained.
>>
>> James
>>
>>> sub prtAll { ... }
>>>
>>>
>>>
>>> --
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>
>>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>


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

Reply via email to