As written, your mail.txt file is only ever going
to have the most recent message in it if you open
the file handle for writing:
open(MAIL, ">/home/brian/mail.txt");
if you want a spool file (list of all messages), you'd need
to open the file handle for appending:
open(MAIL, ">>/home/brian/mail.txt");
While you're at it, you should probably lock the file while you
are writing to it, so the next piece of inbound mail
doesn't try to screw with your mail.txt file while
you are already writing to it.
(this code is ripped from OraPP2ndEd, p 166-7)
flock MAIL, 2;
seek MAIL, 0, 2; # skip to the end for spooling
while (<STDIN>) {print MAIL $_;}
flock MAIL, 8;
close MAIL || die($!);
Note that flock can't be tested with die, since it waits
until the file is "freed up" for locking. If your system
doesn't implement flock, you'll get a fatal runtime error,
AFAIK
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.