http://qs321.pair.com?node_id=1205191

cbeckley has asked for the wisdom of the Perl Monks concerning the following question:

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