【问题标题】:Perl Mime::Lite hash of array derefrencePerl Mime::Lite 数组解引用散列
【发布时间】:2013-08-06 20:52:01
【问题描述】:

我有一个哈希数组,我在 Mime::Litemsg->attach() 函数中取消引用它。代码如下:

for my $href (@$aref){
    $msg->attach(
            Type     => 'text',
            Data     => "productype: $href->{prodtype}   product: $href->{product}    qbs_id:$href->{qbs_id}\n";
    );
}

表示上例中的语法错误。如果这是将msg->attach() 放入循环的正确方法,请告知我,否则我们无法将其保持在循环中。谢谢。

【问题讨论】:

  • $hrefqbs_id 的解引用被破坏(至少在发布的代码片段中)。
  • 我对编辑部分感到困惑。对此感到抱歉。我已经编辑过了。请你再看一遍。
  • 注意 amon 的通知:attach 调用的参数列表仍然以 ; 结尾,这在语法上无效!

标签: perl hash mime


【解决方案1】:

attach 的参数列表中,不能出现分号;。使用逗号, 分隔参数:

for my $href (@$aref) {
    $msg->attach(
        Type => 'text',
        Data => "productype: $href->{prodtype}   product: $href->{product}    qbs_id:$href->{qbs_id}\n",
    );
}

结尾的逗号也可以省略,但我认为这种风格不好。

【讨论】:

  • 我再次编辑了它。请检查。很抱歉造成混乱。
  • 点了。它工作正常。但这是邮件中的附件。我想要它在电子邮件的正文中。请您提出一些建议。谢谢。
  • @deep attach 方法用于构造多部分消息。如果您只想发送一个部分,那么您应该先连接字符串,然后再构建 MIME::Lite 对象。 (此外,MIME::Lite 根据其文档已被弃用)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-31
  • 2014-01-27
  • 2013-12-30
  • 2012-08-03
  • 2013-05-09
  • 2011-11-14
  • 2018-01-16
相关资源
最近更新 更多