in reply to In a perl sub, how do I capture STDOUT, STDERR that comes from another perl sub?
This method sometimes has problems with printing Unicode. (unless you use open ':utf8'; use encoding 'utf8';, which is the right way to go for unicode anyway).sub printInformationWrapper { open (local *STDOUT,'>',\(my $var)); thing that prints to STDOUT return $var; }
This is supposed to work without the pragmata (http://community.livejournal.com/ru_perl/183306.html):
though I've not tested it.{ open (local *STDOUT,'>:utf8',\(my $b="\x{FEFF}")); printing_stuff return $b; }
IO::String is probably a less magical way to tie a filehandle to a string. Then you localize STDOUT like above, assigning your filehandle.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: n a perl sub, how do I capture STDOUT, STDERR that comes from another perl sub?
by blazar (Canon) on Aug 18, 2007 at 09:57 UTC |