in reply to Add values to subroutine inside of a loop.
Construct the hash with the static values first, then add the dynamic ones, then call the sub.
use strict; use warnings; my $added = [ { link => "/var/www/docs", name => "mydocs", }, { link => "/var/www/read", name => "letters", } ]; my @keys = qw( link name ); my $success; foreach my $send_to (@send) { my %send_vals = ( to => 'send_to', account => 'to_account', name => 'name', subject => 'subject', title => 'title', type => 'docs', ); for my $hash (@$added) { for my $key (@keys) { $send_vals{$key} = $hash->{$key}; } } $success = sent (\%send_vals); }
Untested because you haven't defined @send or sent() anywhere.
|
|---|