http://qs1969.pair.com?node_id=11137772


in reply to Assigning printf to a variable

Just as an aside (very tangentially related), if you've got (say) external code in a module you can't easily change with printfs you need to capture you could always locally set STDOUT to a filehandle opened on a scalar ref.

#+begin_src perl :results output drawer use strict; use 5.026; my $output; do { open( my $fh, q{>}, \$output ) or die "Problem redirecting to scal +ar: $!\n"; local( *STDOUT ) = $fh; ## pretend this bit is in some 3rd party module you can't modify printf( "This should go %s", qq{elsewhere} ); }; say qq{\$output is '$output'}; #+end_src #+RESULTS: :results: $output is 'This should go elsewhere' :end:

The cake is a lie.
The cake is a lie.
The cake is a lie.