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!?!?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.
-bcdIn reply to Formatted Output on glob-filehandles by theqblas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |