in reply to Re: Re: Dereferencing an array of hash references
in thread Dereferencing an array of hash references

Perhaps there is a confusion. Your subroutine db_retrieve_records returns a reference to the @loop array, not the @loop array itself. If that is the return value you want for db_retrieve_records, then the mail routine needs correcting.

First, save the reference to @loop:
my $loop = db_retrieve_records();
Then access loop information with the -> dereferencing op:
for my $i (0..@$loop-1) { foreach (qw( action type domain priority target )) { $body .= $loop->[$i]{$_}; } $body .= "\n"; }
Note also that I used @$loop-1 for the last element of the outer loop.

UPDATE: Mr. Freidman's is a much simpler fix. Consider mine as an alternative way to do it :)

-Mark

Replies are listed 'Best First'.
Re: Re: Re: Re: Dereferencing an array of hash references
by mfriedman (Monk) on Jun 26, 2002 at 22:10 UTC
    Simpler, but not identical. Remember that when you say @{ $array_ref } you are making a copy of the array referenced by $array_ref. So your solution is certainly more efficient, in that you are accessing the original array and not making any copies, but it might be somewhat disastrous if you don't want to modify the original array.