Perl Supremos
I have a simple Perl program which produces an HTML file, that I then send via email (using MIME::lite).
My question is, how do I get the contents of my HTML file to be held in memory and passed to sendmail instead of having to write the output to a file first ?
here is the current code
#!/usr/bin/perl use DBI; use DBIx::XHTML_Table; use MIME::Lite 1.137; $user="sybuser"; $server=SERVER; $pass=nopass; open(DAT,">test.html"); print DAT "<HTML>\n"; print DAT "<BODY>\n"; my $dbh = DBI->connect("dbi:Sybase:server=$server", $user, $pass,{ PrintError => 0, # Don't print + warning messages RaiseError => 1 } ); my $table = DBIx::XHTML_Table->new($dbh); $table->exec_query(" select srvname from master..sysservers where srvid=0 "); $table->modify(td => { style => 'color: black; background: yellow; text-align: +center; border: 1', }); print DAT $table->output({ no_head => 1 }); $table->exec_query(" select SPID,Login,Application,DBName from monProcess where +Login not in (NULL,'probe') "); $table->modify(table => { border => 2, width => '100%', }); $table->modify(th => { style => 'color: black; text-align: center; font-weight: + bold', }); $table->modify(td => { style => 'color: black; background: yellow; text-align: +center; border: none', }); print DAT $table->output({ no_head => 0 }); $dbh->disconnect; print DAT $table->output({ no_head => 0 }); print DAT "\n</BODY>\n"; print DAT "\n</HTML>"; close(DAT); my $msg = MIME::Lite->new(From => 'noname@nohost', To => 'someone@nowhere.com', Subject => 'Report', Type => 'text/html', Path => 'test.html'); $msg->send;
I would rather not have to create a temporary html file to do this
e.g. Use MIME::Lite->new(DATA=>'html stuff here'); ?

In reply to HTML file or in-memory ? by Anonymous Monk

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.