Thank you ikegami, I tried Capture::Tiny and it allows to nest wrapping of redirections for STDERR. Example code:
#!/usr/bin/env perl use strict; use warnings; use Capture::Tiny ':all'; sub innerAction { print STDERR "FIRST CAPTURE\n"; # to innerbuffer, works } sub handleInner { print STDERR "INNER before capture\n"; my ($innerBuffer, @results) = capture_stderr { innerAction(); }; print STDERR "INNER past restore\n"; # above goes to console or the outerbuffer, # it fails for outerbuffer when called from handleOuter chomp $innerBuffer; my $no=1; foreach my $line (split("\n", $innerBuffer)) { print "BUFFER (inner): $no; #>>$line<\n"; $no++; } } sub outerAction { print STDERR "OUTER before call\n"; # to outerbuffer handleInner(); print STDERR "OUTER past call\n"; # to outerbuffer } sub handleOuter { print STDERR "OUTER BEFORE CAPTURE\n"; my ($outerBuffer, @resuts) = capture_stderr {outerAction();}; print STDERR "OUTER PAST RESTORE\n"; chomp $outerBuffer; my $no=1; foreach my $line (split("\n", $outerBuffer)) { print "BUFFER (outer): $no; #>>$line<\n"; $no++; } } handleInner(); print "################################# \n"; handleOuter();
Produces this output which shows that the outer redirect continues when the inner redirect is done.
INNER before capture INNER after restore INNER past restore BUFFER (inner): 1; #>>FIRST CAPTURE< ################################# OUTER BEFORE CAPTURE BUFFER (inner): 1; #>>FIRST CAPTURE< OUTER PAST RESTORE BUFFER (outer): 1; #>>OUTER before call< BUFFER (outer): 2; #>>INNER before capture< BUFFER (outer): 3; #>>INNER past restore< BUFFER (outer): 4; #>>OUTER past call<
BTW: Account creation is really a pain here. And only 10 letters for passwords?

In reply to Re^2: Nested redirect for STDERR to a string buffer within a perl program by Anonymous Monk
in thread Nested redirect for STDERR to a string buffer within a perl program by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.