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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Assigning printf to a variable
by haukex (Archbishop) on Oct 20, 2021 at 08:04 UTC | |
by pryrt (Abbot) on Oct 20, 2021 at 14:56 UTC | |
Re^2: Assigning printf to a variable
by Bod (Parson) on Oct 20, 2021 at 12:19 UTC | |
by pryrt (Abbot) on Oct 20, 2021 at 14:43 UTC |
In Section
Seekers of Perl Wisdom