Dear Monks,
I need to write some recursive subroutine that in each entry has to
-
save STDOUT and STDERR,
- change it to redirect them to some files,
- do something with them and call itself under
the apropriate conditions
- recover the old values.
I know how to do it using "old style" with the ">&"
descriptor. I.e. something
like:
my $log = ...;
my $err = ...;
open(SAVEOUT, ">&STDOUT") or die ...
open(STDOUT,"> $log") or die ..
open(SAVEERR, ">&STDERR") or die ...
open(STDERR,"> $err") or die ..
but I need to use lexical variables $SAVEOUT, and $SAVEERR
instead of global variables. The problem being
that to recover the old values I have now:
open(STDOUT, ">&SAVEOUT");
open(STDERR, ">&SAVEERR");
I assume that this construction will not work If I use
it with lexical variables? i.e.
open(STDOUT, ">&$SAVEOUT");
open(STDERR, ">&$SAVEERR");
How can I do it?
Thanks!
Casiano
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.