> 
> # test::load
> package test::load;

use strict;
use warnings;

> require Exporter;
> our @ISA = qw/Exporter/;
> our @EXPORT = qw/new copy/;
> 
> sub copy 
> {  my $self ;

This is very confusing code. $self is generally used for the instance
you are acting on. 'copy' is also an odd choice, some prefer 'clone' (if
that is really what you are intending but I can't tell).

>      my $x = shift;
>      my $y = $x -> {B};

Are you sure B has in it what you think? See below.

>      $y .= $y;
>      $self -> {YY} = $y;
>      bless $self;

perldoc -f bless

I am not sure you are fully understanding bless. Generally you want to
use the 3 argument form to provide for inheritance, and to avoid other
issues.

>      return $self;
>  } 
> 
> sub new
> { my $self;
>      $self -> {A} = shift;
>      $self -> {B} = shift;
>      

Again, $self is generally (in a constructor) used to hold the class.  Do
you really want A to be 'AAA' and B to be '111'?? Or were you expecting
'AAA' to be '111'.  These are very very poor names.

> bless $self;

See comments above about bless.

>      return $self; 
> }
> 1;
> __END__
> 
> 
> # main
> use test::load;
> 
> my $x = test::load -> new ( AAA => 111 );

Just a style issue, Perl provides the following alternate syntax (that
is not required).

my $x = new test::load ( AAA => 111 );

You might also consider using mixed case package names, generally all
lowercase and all upper case package names are reserved for core features.

perldoc perlstyle

> my $y = $x ->copy ;
> my $z = $y;
> 
> $y->{YY} = 100;
> print $z -> {YY};
> __END__
> 
> Question :
> How can I make $z become another (blessed) thing ?
> So when I modify something in $y , and not affecting $z ?
> 

You can't, at least in the way I think you mean. C<bless> is just
another function, you can bless (just about) anything. So $z is
blessable, by just saying,

bless $z;

Are you talking about cloning $y?  The code you provided is just copying
the reference to the instance.  

Have you read the documentation on references,

perldoc perlreftut
perldoc perlref

And the documentation on Perl OOP,

perldoc perlboot
perldoc perltoot
perldoc perltooc
perldoc perlbot

> Thanks in advise,
> Bee
> 

Tell us what you are really trying to do, give us real classes, method
names, and variables.  Are you trying to clone objects? Your pseduo-code
is very difficult to follow and does not illustrate your questions.

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>


Reply via email to