1

我正在尝试在我的 Windows 平台上安装 scmbug。我在以下方法中将哈希作为参考错误。查看“HERE”注释以了解它发生的位置。

我应该用其中的 $mail 替换每个 %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);
   }
}

谢谢

4

2 回答 2

3

文档:perldoc perlref

你有一个 hashref,但你正在使用一个 hash 的印记。全部替换%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}`. 
于 2012-11-14T17:46:26.447 回答
1

用于$mail->{ ... }取消引用。但是在您的情况下,您有一个哈希%mail而不是引用,因此访问其成员的正确方法是没有取消引用运算符->。一个$mail{...}就足够了。

于 2012-11-14T17:46:32.393 回答