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

I have a subroutine that returns an array reference containing a list of users that I want to send mail to but always from the first user in the list.

The problem is, I think, that MIME::Lite cannot extract the users from the memory address?
"Cannot extract <mem. address here> from ARRAY<mem. address here>"

Any ideas??
sub get_users_array { my ($href, $index) = @_; my @all_users; my @sg_keys = keys %$href; foreach my $key (@sg_keys) { my $rec = $href->{$key}; foreach my $mailbox ( sort keys %{ $rec->[$index] } ) { my $users_ref = $href->{$key}[$index]{$mailbox}; push @all_users, $users_ref; } } return \@all_users; } $users_ref = get_users_array(\%sg_hash, $mbx_index); foreach my $user ( @{$users_ref} ) { my $to = $user."@".$domain; my $from = $user->[0]."@".$domain; if ($::Debug) { print "INFO: Sending email to $to\n" } my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $subject, Type => 'multipart/mixed' );

Replies are listed 'Best First'.
Re: Fun w/ Elaborate data structures
by poj (Abbot) on Feb 08, 2003 at 17:30 UTC
    Try this :
    foreach my $user ( @{$users_ref} ) { my $to = $user."@".$domain; # my $from = $user->[0]."@".$domain; # wrong my $from = $users_ref->[0]."@".$domain; # correct ..
    poj
      Thanks, must have caught a mild case of dereferencing dementia.

      --ERick