我正在尝试在我的Windows平台上安装scmbug。 我在下面的方法中将Hash作为参考错误。看到“HERE”注释,看看它在哪里发生。
我应该用$ mail替换每封%邮件。
我尝试了这个,但还有其他错误。说
全局符号“$ mail”需要显式包名称
如何解决此问题?
sub mail_notification_send_mail {
my $self = shift;
my ($request, $subject, $message, $mailing_list) = ( @_ );
my %mail;
# Set values. This permits users to override the default behavior
# of Mail::Sendmail
%mail = \%{ $request->{ policies }->{ mail_notification }->{ mail_settings } };
%mail->{ 'X-Mailer' } = "Mail::Sendmail version $Mail::Sendmail::VERSION"; HERE
%mail->{ Subject } = $subject; HERE
%mail->{ Message } = $message; HERE
#
# Since we just reset %mail to values, we haven't really picked up
# the To,From,Reply-To that were computed. We do this next
#
# Don't blindly ignore the To list that was computed
my $mailing_list_to = $self->emails_to_csv( $mailing_list->{ To } );
%mail->{ To } = $mailing_list_to; HERE
# Don't blindly ignore the From list that was computed
my $mailing_list_from = $self->emails_to_csv( $mailing_list->{ From } );
%mail->{ From } = $mailing_list_from; HERE
# Don't blindly ignore the 'Reply-To' list that was computed
my $mailing_list_replyto = $self->emails_to_csv( $mailing_list->{ 'Reply-To' } );
%mail->{ 'Reply-To' } = $mailing_list_replyto; HERE
if ( !sendmail(%mail) ) {
my $msg = "Sending mail on " . $request->{ name } .
" failed. Log error was:\n" . $Mail::Sendmail::error . "\n";
$request->add_result(1, $msg);
}
}
由于
答案 0 :(得分:3)
你有一个hashref,但是你正在使用哈希的sigil。将所有%mail
替换为$mail
。
你有:
%mail = \%{ $request->{ policies }->{ mail_notification }->{ mail_settings } };
\%
告诉perl取消引用散列并返回hashref,但是您将其分配给散列。我打赌你也会收到警告。该行应该是:
$mail = $request->{ policies }->{ mail_notification }->{ mail_settings }; ## change all `%mail` to `$mail`
或
%mail = %{ $request->{ policies }->{ mail_notification }->{ mail_settings } }; ## change all `%mail->{something}` to `$mail{something}`.
答案 1 :(得分:1)
使用$mail->{ ... }
进行取消引用。但在您的情况下,您有一个哈希%mail
而不是引用,因此访问其成员的正确方法是没有解除引用运算符->
。简单地$mail{...}
就足够了。