in reply to Re^4: Error in MIME::Lite?
in thread Error in MIME::Lite?

You can't create a new empty object and add data to it.

Sure you can

#!/usr/bin/perl -- use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new; ## no data $msg->build( qw/ to you from me Data Data1 /); ## data $msg->build( qw/ subject SUBJECT /)->data('Data2'); ## data $msg->attach( qw/ Data DATA3 /); ## data $msg->print; __END__ Content-Transfer-Encoding: 7bit Content-Type: multipart/mixed; boundary="_----------=_150136405630120" MIME-Version: 1.0 Date: Sat, 29 Jul 2017 14:34:16 -0700 To: you From: me Date: Sat, 29 Jul 2017 14:34:16 -0700 Subject: SUBJECT X-Mailer: MIME::Lite 3.029 (F2.84; T2.04; A2.12; B3.14; Q3.13) This is a multi-part message in MIME format. --_----------=_150136405630120 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain Data2 --_----------=_150136405630120 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-Type: text/plain DATA3 --_----------=_150136405630120--

Replies are listed 'Best First'.
Re^6: Error in MIME::Lite?
by littlelion (Novice) on Jul 30, 2017 at 00:37 UTC
    Aha! There's the issue:
    % diff foo.pl bar.pl 7c7 < $msg->build(subject => 'a message subject')->data('Data2'); --- > $msg->build(subject => 'a message subject'); foo.pl -> 0 bar.pl -> 1
    Why is the ->data() required?

      Because its written that way?

      build returns an object of some kind ... if you dont specify data in constructor, you have to specify it later ...

      Notice also data1 is disappeared :)