radagast has asked for the wisdom of the Perl Monks concerning the following question:

Hello all. I have a rather simple question, almost embarrased to ask it. There's a subroutine I need to use that returns a reference to an array such as:
$ref = $foo->get_body();
It's from Mail::Folder::Mbox and It's supposed to return the message body as an array. I'm almost embarrassed to be asking this.
--- "I slept with Faith, and found a corpse in my arms on
awaking; I drank and danced all night with Doubt, and found
her a virgin in the morning." Aleister Crowley, _The Book of Lies_

Replies are listed 'Best First'.
Re: Returning references
by ChOas (Curate) on Jan 19, 2001 at 16:43 UTC
    Try this, my friend:
    my @Message=@{$ref};

    That'll dereference it...

    GreetZ!,
      ChOas

    print "profeth still\n" if /bird|devil/;

      Or (cutting out the middle man... er... variable :)

      @Message = @{ $foo->get_body() };
      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

Re: Returning references
by andye (Curate) on Jan 19, 2001 at 16:50 UTC
    Hi there radagast... the answer above is right (if that was your question), but in more general terms, there's a very clear explanation of reference syntax in Effective Perl Programming, which I can recommend highly.

    Andy.

Re: Returning references
by mr.nick (Chaplain) on Jan 19, 2001 at 19:42 UTC
    Or just start using it as $ref without moving it to another variable:

    print join "\n",@$ref; # treat it as an array print $ref->[0]; # grab the first element for my $l (@$ref) { print $l; } # loop over it and do something

    You don't need to move it to another variable for it to be useful. You just need to know the syntax to dereference it on the fly.