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

how does one print to the screen in html and email output simultaneously? Is there a command that combines the two functions? I would feel dumb copying every print statement as a print MAIL statement too! There are lots of tests to determine what is printed so I don't think a loop will do! Would love some suggestions

Replies are listed 'Best First'.
Re: printing and mailing
by chromatic (Archbishop) on May 02, 2001 at 06:35 UTC
    This is very similar to a question answered in perldoc perlfaq5, namely How do I print to more than one file at once?.

    If you open multiple filehandles and add everything to one big string, it's easy to write a loop. The other suggestions depend on being able to install stuff locally or having Unix commands available.

    The IO::Tee module on the CPAN is another solution.

Re: printing and mailing
by rchiav (Deacon) on May 02, 2001 at 06:39 UTC
    There are probably a lot of ways to do what you're looking to do, but unfortunately no one is going to be able to give you the best way without seeing your code.

    But without seeing it, you could do several things. One would be to put all the lines to be printed into an array and then pass that array to a sub to print it and then a sub to mail it. Another would be to do both at the same time as the text is generated or evaluated. This all really depends on the overall scope of what you're doing though.

    Rich