I know you've received other responses, but I'm doing a good bit of
this lately.
sub sendEmail {
open (Sendmail, "|/usr/lib/sendmail -oi -t ")
or die "Can't fork for sendmail: $!\n";
print Sendmail "EOF";
From: Bugs amy\@longsys.com
To: amy amy\@longsys.com
Subject: Test Create
test create
EOF
close(Sendmail);
}
As someone mentioned on the board (ever so briefly), here-documents
like this one require that your "sentinel" string have no leading
whitespace.
e.i., you may say
$var=END;
This is my variable's
multiline text,
complete tith tabs\t\t and extra newline\n\n, etc
END
but you *can't* say
$var=END;
blah
END
because here, END has space in front of it.
In several shells you can put tabs in front of it if you say
print-END; # the dash says "let me use a leading tab"
blah
tab hereEND
but I'm not sure what Perl thinks about that (I don't think it likes
it), and even in shells, it usually has to be tabs, not just
whitespace.
Note also (and please forgive me if I'm rambling =o) that the default
interpolation is double-quotish, so
printEND;
is exactly equivalent to
print"END";
Both tell Perl (or the shell) to do string interpolation on the
here-doc, so you can embed variables. On the other hand,
print'END';
means use single-quotish behavior, and won't interpolate the vars,
which is sometimes useful. And yes, this does mean that you can use
print`END`;
ls -l
echo "Hi, Mom!\n\n"
END
...though there are probably better ways to perform such chicanery. :o/
I've found only sparse documentation for this trick (at least in basic
perl-specific docs), but use it a pretty good bit, especially in CGI's
that are going to send a lot of JavaScript (or some such) to the
client. It's a reasonably readable way to practically switch languages
mid-script, but gives you access to some neat tricks via interpolation.
e.g.,
#~
$JS=END;
// now writing JavaScript
function foo(bar) {
// blah, $blah, $bleep{$glurf}
}
function bar(foo) {
// blah, blah
}
END
# and back to "pure" Perl ( =o)
print $query-header,
$query-start_html(-title = $title,
-script = $JS, # the above JavaScript
-onLoad = "foo($x);",
), "\n";
#__
The biggest problem (for me, anyway) is that it throws off my
formatting to have to stick in that line with no leading whitespace.
I do it anyway a lot of the time, but if that's a problem, there's
always (well, usually, lol) qq{}. e.g., the above example, rewritten,
would be
$var = qq{
blah
};
Again, forgive me if you knew that.
As a seperate problem, your example has whitespace in front of the
"From:", "To:" and "Subject:" headers as well -- I can't say I'm an
expert on those, but does that work? Might want to test it to be sure.
In the end, all things considered, it might work better to just build
it the hard way --
print Sendmail "To:...\n",
"From:...\n",
"Subject:...\n\n", # note double newline
# content stuff here
"\n";
One more consideration -- I believe the specs demand a blank line after
all the headers, to signify that "the text starts *here*".
Hope that helps. =o)
And if not, sorry for rambling so! lol!
Paul
"Government should be like cooking a small fish -- don't overdo it."
-- Lao Tzu
__
Do You Yahoo!?
Yahoo! Photos -- now, 100 FREE prints!
http://photos.yahoo.com