Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Redirecting STDOUTby tame1 (Pilgrim) |
on Jun 14, 2002 at 13:30 UTC ( [id://174507]=perlquestion: print w/replies, xml ) | Need Help?? |
tame1 has asked for the wisdom of the Perl Monks concerning the following question:
I find myself in need of a way of redirecting/capturing STDOUT, but from within and program instead of from the command line. In detail, here is the problem. We use a home grown templating system in which the template holds some perl and lots of html, with a bunch of $href->{somekey} entries. That template is slurped up, and then eval'ed (with $href having been created/filled before the slurp and eval). The slurped template can be edited by non-programmers, so for safety we 'use Safe'. Here is the code so far: The real problem now comes up. ANY use/call of $code->($href) will activate the print statements inside the slurped file. This was fine with the following: But now I am trying to instead grab the output of $code and stick it as text into an email. (You guessed it - I'm trying to email generated web pages - HTML email, yuck!). Surfing through the various books, I find no simple way to redirect STDOUT to a variable for capture. The following code failed miserably: Any of you geniouses know offhand how I can get this darned HTML output from the code ref $code into a simple variable so i can give it to MIME::Lite as data? Much gracious bowing and licking of boots are offered to the one who can solve this for me! What does this little button do . .<Click>; "USER HAS SIGNED OFF FOR THE DAY"
Back to
Seekers of Perl Wisdom
|
|