Indeed, object constructors return a reference. In general, you should just use that reference without further indirection.
my $Object = ObjectMaker->new(); Foo::DoSomething(foo, bar, $Object); $Object->MethodName(blah);
You only need to do Foo::DoSomething(foo, bar, \$Object); in the very uncommon case where you want DoSomething to be able to change where your reference ($Object) points to.
Updated to be add more details: for example,
DoSomething(foo, bar, \$Object); print $Object; # prints "42" sub DoSomething { my $foo = shift; my $bar = shift; my $Object = shift; $$Object = 42; }
Now the caller will notice that his $Object is not longer an object reference but a scalar with value 42! This way of passing parameters by reference so that they can be modified is very common in C and Fortran, but not so common in Perl
In reply to Re: Using Objects across files and packages
by itub
in thread Using Objects across files and packages
by Bobc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |