And here are the relevant subs that create and attempt to extract the data for mailing. Can anyone tell me what I'm doing wrong here? In it's current form (I've attempted all sorts of dereferencing), I get the error "Bad index while coercing array into hash".$VAR1 = { 'target' => '1.1.1.1', 'id' => '1025116394', 'session' => '1025116375.79921', 'domain' => 'test.com', 'type' => 'A', 'priority' => undef, 'action' => 'add' }; $VAR2 = { 'target' => 'test.com', 'id' => '1025118001', 'session' => '1025116375.79921', 'domain' => 'www', 'type' => 'CNAME', 'priority' => undef, 'action' => 'add' };
sub db_retrieve_records { my $select_query = "SELECT * from records where session=$sessi +on"; my $sth = $dbh->prepare($select_query); $sth->execute(); my %sessions; while (@records_results = $sth->fetchrow_array) { my $id = $records_results[0]; $sessions{$id}{id} = $id; $sessions{$id}{action} = $records_results[2]; $sessions{$id}{domain} = $records_results[3]; $sessions{$id}{priority} = $records_results[4]; $sessions{$id}{target} = $records_results[5]; $sessions{$id}{type} = $records_results[6]; $sessions{$id}{session} = $session; } foreach my $key (sort keys %sessions) { push(@loop,\%{$sessions{$key}}); } return \@loop; }
sub mail { local $self = shift; local $dbh = $self->param('dbh'); my $q = $self->query(); local $session = $q->param('session'); my %master_info = db_retrieve_master_info(); my @loop = db_retrieve_records(); my $head = Mail::Header->new; $head->add(From => 'somebody@localhost'); $head->add(To => $master_info{$session}{email}); $head->add(Subject => "Summary of DNS Request"); my $body .= "\n"; foreach (qw( account domain )) { $body .= "$_ $master_info{$session}{$_}\n"; } $body .= "\n"; for my $i (0..@loop) { foreach (qw( action type domain priority target )) { $body .= $loop[$i]{$_}; } $body .= "\n"; } # $body .= Data::Dumper->Dump(@loop); $body .= "Other Instructions: \n" if $master_info{$session}{ot +her}; $body .= "$master_info{$session}{other}\n"; my $mail; $mail = Mail::Internet->new(Header => $head, Body => [$body], Modify => 1, ); my $success = $mail->send('sendmail'); }
In reply to Dereferencing an array of hash references by fuzzyping
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |