I have this script sends a report either to STDOUT or to an e-mail address via a library that is a subclass of Mail::Send.

What happens is that based on some command-line option, I am setting the variable $message to either *STDOUT or to $mail_obj->open() (Which returns a bless'ed glob of Mail::Mailer::smtp), I then select($message) and set $~ and $^ to the appropriate format names.

Anyway, when I try to write($message), the output seems to disappear when $message is the Mail::Mailer::smtp object, but when sent to STDOUT it works: e.g.

---- CODE BLOCK ---- { if($opt_mailto) { $mail_obj = VNI::Mailer->new(); $mail_obj->to($opt_mailto); $mail_obj->subject($report_title); $mail_obj->from($from); $message = $mail_obj->open(); } else { $message = *STDOUT; } # select whatever filehandle is in $message for output select($message); # -- further down format MSG_TOP = blah some header for this report --------------------------------- . format MSG = @<<<<< @<<<<<< @<<<<<< @<<<<<< $foo, $bar, $baz, $quux ------------------------------ . $^ = "MSG_TOP"; $~ = "MSG"; foreach (@lusers) { $foo = $_->data; $bar =$_->otherdata; # etc, etc, # THIS WRITE WORKS WHEN $message == *STDOUT # OUTPUT DISAPPEARS OTHERWISE write($message); } # The following prints always work correctly. print $message "Some summary info: $balance\n"; print $message "People who suck: $sucky\n"; } ----- END CODE ----

So when I try doing this using the mail object, all I get is the summary information, but not the report itself.

Why? Why!?!?

This is perl 5.0005_4 on FreeBSD 4.4-STABLE

I tried a few different tricks and none of them worked, and one of the techniques actually caused perl to segfault!

I would think that write() is just a front-end for print(), so I don't know why print() would use the mail-filehandle correctly and write() not. Argh.

-bcd

In reply to Formatted Output on glob-filehandles by theqblas

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.