Carl Jolley wrote:

> On Fri, 8 Feb 2002, $Bill Luebkert wrote:
> 
> 
>>Carl Jolley wrote:
>>
>>
>>>I you want a subroutine to return a reference then the only way
>>>for that to happen is that the subroutine has to return the
>>>reference. There is no way that I know of, external to a subroutine,
>>>to get reference to the subroutine's return value. You of course
>>>can get the subroutine's return value and create a reference to
>>>it but that's not exactly what I think you are looking for.
>>>
>>I believe you can do what he is asking, but you must know what the
>>routine is returning to do it properly.
>>
>>For scalar ref:
>>      $self->{_result} = \$some_obj->some_method;
>>
>>vs array ref:
>>
>>      $self->{_result} = [$some_obj->some_method];
>>
>>Of sourse technically you are creating a ref to the return value.
>>
>>
> 
> I'm not sure what
> 
>  $self->{_result} = \$some_obj->some_method;
> 
> generates (? a reference to the code?) but it seems to me that:
> 
>  $self->{_result} = [$some_obj->some_method];
> 
> would have _result be reference to a single element anonymous array
> containing whatever scalar value that the method returned. I don't belive
> that technically (or otherwise) it would generate a reference to the value
> returned by the method even if the method returned an array reference.


Did you try it ?  Didn't use an object on left side since it isn't necessary 

to prove the point.

use strict;
use Data::Dumper; $Data::Dumper::Indent=1;

my $obj = new fubar;

my $foo = \$obj->foo;
print "\$\$foo = $$foo\n";
print &Data::Dumper::Dumper($foo);
print "\n";

my $bar = [$obj->bar];
print "\@\$bar = @$bar\n";
print &Data::Dumper::Dumper($bar);

package fubar;

sub new {
        my $class = ref ($_[0]) ? ref (shift) : shift;
        my $self = { };
return bless $self, $class;
}

sub foo {
return 4;
}

sub bar {
return (1, 2, 3);
}

__END__


-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to