http://qs321.pair.com?node_id=584517

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

Hey everyone,

I have a situation at work in which managements desired solution is an email, .forward, and a perl script. Basically, it needs to process the email content, do some db stuff, and log some stuff.

As this is the first time I've done something like this, there's one thing in particular I do not understand. When I do this:

#!/usr/bin/perl while (<STDIN>) { -- process the email content } -- do the db stuff here open(FILE, ">logfile"); ---write to logfile close(FILE);
The file does not get opened and written to.

However, when I do this:

#!/usr/bin/perl open(FILE, ">logfile"); while (<STDIN>) { -- process the email content } -- do the db stuff here ---write to logfile close(FILE);
the file does get opened and written to.

My guess is that it has to do with I/O and buffering. The only thing I could think of was to set  $|=1;, but that didn't work. I could do it the second way, since its pretty trivial, but I would really like to know how to do it the first way.

As always, thanks for your wisdom

davidj