in reply to Re: Re: Re: Returning multiple values from a function
in thread Returning multiple values from a function

fyi, exactly what I did was this
my $type; %results = findResults(\$type);

$type is then modified inside findResults() but only the hash is passed back to the caller. So the value of $type is changed but never passed back,so as to avoid slurpage


Is this ok style? or is that a little too C++?

You can return only a scalar or a list from a function. To get a hash return, you either have to flatten it into a list (and reconstruct it at the other side) or return a reference to the hash

I haven't found this to be so, unless perl is taking care of the reconstruction for me. I returned a hash like so  return %results; and the calling hash was populated correctly. I was able to do a foreach over each of the keys i had set. Perl is taking care of the reconstruction correct?

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Returning multiple values from a function
by castaway (Parson) on Sep 04, 2003 at 07:35 UTC
    I haven't found this to be so, unless perl is taking care of the reconstruction for me. I returned a hash like so return %results; and the calling hash was populated correctly. I was able to do a foreach over each of the keys i had set. Perl is taking care of the reconstruction correct?

    Yes, Perl takes care of that for you. The sub returns a list of values from the hash, and the assignment turns that list back into a hash. (You could return a hash, and assign to an array, you'd then get an array containing the keys and values of the hash, alternated.)

    That make any sense?

    C.