theqblas has asked for the wisdom of the Perl Monks concerning the following question:
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.
-bcd
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Formatted Output on glob-filehandles
by Thelonius (Priest) on Oct 24, 2002 at 20:10 UTC | |
|
Re: Formatted Output on glob-filehandles
by Jenda (Abbot) on Oct 24, 2002 at 20:46 UTC | |
by theqblas (Initiate) on Oct 24, 2002 at 21:37 UTC | |
|
Re: Formatted Output on glob-filehandles
by VSarkiss (Monsignor) on Oct 24, 2002 at 19:51 UTC | |
by theqblas (Initiate) on Oct 24, 2002 at 20:06 UTC |