in reply to An object replacing itself

If I understand correctly, you want the object in the client code to become a different object when a particular method is called on it, correct? If this is want you want you can simply assign the new object to $_[0] in the method. See below:

#File Foo.pm package Foo; sub change_var { $_[0] = 'Bar'; } # File main.pl use Foo; my $var = 'Foo'; print "$var\n"; # prints "Foo" Foo::change_var($var); print "$var\n"; # prints "Bar"

In Perl the @_ array actually contains the arguments passed to the subroutine. Modifing @_ directly modifies the variable in the clients namespace. Does that make sense?

May the Force be with you

Replies are listed 'Best First'.
Re^2: An object replacing itself
by ryantate (Friar) on Sep 23, 2004 at 20:50 UTC

    I'll try that, I may have made a bad assumption about something I tried before ...