On Tuesday 19 March 2013 10:51:08 Chris Nighswonger wrote:
> I'm sorry: I should have worded my question directly. Here is what I need
> to do:
>
> open STDOUT, ">", \$var
>
> So long as I have STDOUT write to a file, things work fine. when attempting
> to write to a variable, Perl borks.
Ok, that would not work, since this is just some Perl trickery and nothing
really gets written to any file handle.
But you can use just the same trick in Python:
use Inline Python => <<'PYTHON';
import sys
from cStringIO import StringIO
sys.stdout = capturer = StringIO()
def print_stuff():
print "hello world"
def get_printed():
return capturer.getvalue()
PYTHON
print_stuff();
print 'Perl got: ', get_printed();
Regards,
Stefan