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.
In reply to Re: n a perl sub, how do I capture STDOUT, STDERR that comes from another perl sub?
by akho
in thread In a perl sub, how do I capture STDOUT, STDERR that comes from another perl sub?
by seank
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |