Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Good Morning!

I have a small issue that I told myself I was going to ignore because the script works just fine ... but here we are.

The script monitors replication between two databases by updating a string field on the source with a timestamp, waiting a bit, retrieving the value from the target, and sending an email if they're not the same.

None of which matters because that stuff all works. And the part that doesn't work is purely cosmetic, but it's bugging me.

I've included a runnable stripped down sample script below, but the crux of the matter is this:

$source_heart_beat_timestamp = "20171207_113255"; $target_heart_beat_timestamp = "bar"; $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_tim +estamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp";

When  $source_heart_beat_timestamp contains something that looks like a timestamp, the trailing eol gets eaten, but only in the email body. It works fine with  say.
When  $source_heart_beat_timestamp contains "foo", the trailing eol is displayed properly both on stdout and in the email.

So, when  $source_heart_beat_timestamp contains "20171207_113255"
stdout looks like:

local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar

but the email body looks like:

local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeSta +mp: bar

However, when  $source_heart_beat_timestamp contains "foo"
both stdout and the email body look like:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar

Who's eating the eol?
At this point I'm willing to blame the dog, but if anybody could point me toward a more likely suspect, I would greatly appreciate it.
As would the dog.

Thanks,
cbeckley

Here's the whole script:

#!/usr/bin/perl use strict; use warnings; use v5.16; use MIME::Lite; my $source_heart_beat_timestamp = ''; my $target_heart_beat_timestamp = ''; sub local_do_mail { my ($msg_body) = @_; my $msg = MIME::Lite->new( From => 'cloudops@foo.com', To => 'cbeckley@foo.com', Subject => 'testing missing eol', Data => $msg_body ); $msg->send; } # # The mail output here includes the \n after the source_heartbeat # $source_heart_beat_timestamp = "foo"; $target_heart_beat_timestamp = "bar"; my $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_ +timestamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp"; say "local_do_mail:\n$output_msg"; local_do_mail("local_do_mail:\n$output_msg"); # # The mail output here does not include the \n after the source_heartb +eat # $source_heart_beat_timestamp = "20171207_113255"; $target_heart_beat_timestamp = "bar"; $output_msg = "Source Heart Beat TimeStamp: " . $source_heart_beat_tim +estamp . "\n"; $output_msg .= "Target Heart Beat TimeStamp: $target_heart_beat_timest +amp"; say "local_do_mail:\n$output_msg"; local_do_mail("local_do_mail:\n$output_msg");

And here are the outputs on stdout and in the emails, respectively:

Stdout:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeStamp: bar

And the bodies of the two emails:

local_do_mail: Source Heart Beat TimeStamp: foo Target Heart Beat TimeStamp: bar
local_do_mail: Source Heart Beat TimeStamp: 20171207_113255 Target Heart Beat TimeSta +mp: bar

In reply to Losing eol character using MIME::Lite by cbeckley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others about the Monastery: (2)
    As of 2025-06-22 15:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.