newbieperlperson has asked for the wisdom of the Perl Monks concerning the following question:
Hi there,
I am having issues with the format of the emails sent via MIME::Lite.
I am outputting two items of data per line. The first column of data is not fixed length, and I want the second item of data to be correctly aligned in the same position each time so I am using sprintf to format the data.
The print command output illustrates that the data is been outputted correctly but when I receive my email the data is all over the place.What I did notice in my eclipse Perl environment that the string is padded out exactly like it outputs in my email, yet the print statement shows the data correctly aligned!!!
Any help on why the formatting is all over the place would be appreciated. The mailer is doing its job correctly and working with the data given. The problem seems to be with how sprintf holds the data internally.use MIME::Lite; $smtp = "mailserver"; $internal_email_address = 'myemailaddess'; $a = sprintf ("%-90s %-s\n", "the amount for Apple is ","34"); $b = sprintf ("%-90s %-s\n", "the amount for Lemons is", "7"); print $a; print $b; $c = $a.$b; mailer( $internal_email_address,"issue", $c); sub mailer { my ( $addr, $subj, $output ) = @_; print "$_\n" for $addr; print "$_\n" for $subj; print "$_\n" for $output; $msg = MIME::Lite->new( From => 'xxxx', To => $addr, Subject => $subj, Data => $output ); MIME::Lite->send( 'smtp', $smtp, Timeout => 60 ); eval { $msg->send }; $mailerror = "Status: ERROR email - MIME::Lite->send failed: $@\n" + if $@; if ( $mailerror eq '' ) { $status = "Status: Mail sent\n"; } else { $status = $mailerror; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sprintf format and print inconsistencies whilst creating fixed width column
by roboticus (Chancellor) on Dec 19, 2013 at 19:45 UTC | |
by newbieperlperson (Acolyte) on Dec 19, 2013 at 19:52 UTC | |
by newbieperlperson (Acolyte) on Dec 20, 2013 at 02:28 UTC | |
by roboticus (Chancellor) on Dec 20, 2013 at 13:59 UTC | |
|
Re: MIME::Lite formatting issues
by toolic (Bishop) on Dec 19, 2013 at 18:57 UTC | |
by newbieperlperson (Acolyte) on Dec 19, 2013 at 19:27 UTC | |
|
Re: MIME::Lite formatting issues
by karlgoethebier (Abbot) on Dec 19, 2013 at 19:00 UTC | |
by newbieperlperson (Acolyte) on Dec 19, 2013 at 19:29 UTC |