Tuna has asked for the wisdom of the Perl Monks concerning the following question:

I am lost here. I have a program which automatically generates an email, based upon a particular configuration file. The way the program was written, it simply prints to <STDOUT>. I am trying to modify it to print to a temporary file, send an email who's body is this temporary file, unlinking the temporary file, then exit.

Here's some code:
use IO::File; my $fh = IO::File->new_tmpfile() || die "Can't make tmp file: $!"; my $FORMAT ="%-4s %-15s %-16s %-16s %-6s %-6s %-8s %s"; open (FILE, ">$fh")|| die "Can't open temp file: $!\n"; select ($fh); # this is an example of how I have coded all of my print statements ###################### # Print Router Table # ###################### print FILE <<TABLE The following table contains pertinent information regarding the routers listed in this flow request. TABLE ; printf FILE ($TAB, "Item", "Router", "Type", "IOS Version", "Memory", "Engine(s)", "\n"); printf FILE ($TAB, "====","================","====","===========", "=======","===========", "\n"); $counter = 0; foreach $key (sort keys %router_of_interest) { if (exists $version{$key} && $router_type{$key} && $memory{$key} && $engine{$key}) { $counter++; printf FILE ($TAB, "$counter.", "$key", "$router_type{$key}", "$version{$key}", "$memory{$key}K", "Engine $engine{$key}", "\n"); } }
Here's how I intend on sending mail
open(MAIL,"|/usr/lib/sendmail -t") || die "Can't open sendmail: $!"; print MAIL <<REQUEST To: <me\@work.com> Subject:Flow Export Request - $request_date REQUEST ; close(MAIL);
My question is how do I accomplish using my temporary file, "FILE", as the text of an my email?

Thanks, as always,

Steve

P.S. Yes, I'm using  use strict; and -w. All the above variables are declared, and contain the values that I expect :)

Replies are listed 'Best First'.
Re: Using temporary file as body of email
by THRAK (Monk) on Apr 20, 2001 at 00:20 UTC
    I'm a little short on time at the moment so there's not a lot of thought here, but a couple of quick things...
    1) Why create the temp file and mail that? Why not create a $msg variable on the fly by substituting the config values from a template. Or you could build the whole format on the fly and save it in $msg. Then just send $msg.
    2) You may want to look into Net::SMTP instead of just piping to sendmail. Fewer pitfalls.

    -THRAK
    www.polarlava.com
A reply falls below the community's threshold of quality. You may see it by logging in.