Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
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? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2023-09-22 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?