I have been working my way through several sections of Peter Wainwright's "Pro Perl." I was, in particular, interested in his approach to redirecting Perl's STDOUT and STDERR filehandles. I entered his code (see below) and got an odd result that I don't understand and, after researching it, can't find any indication of what is going on.

Here is the code snippet:

open(OLDOUT, "> &STDOUT"); my $logfile = 'MyLearn01_log.txt'; open(STDOUT, "> $logfile"); select STDOUT; <...do whatever printing to the new STDOUT...> close(STDOUT); open(STDOUT, "> &OLDOUT);

When I run this snippet I found that a file &STDOUT had been created, as well as the $logfile, MyLearn01_log.txt.

I understand, of course, why the logfile was created. But I don't understand why the file, &STDOUT, was created.

The book doesn't say anything about it (in fact my read is that no such thing should have happened).

I am running version 5.8.8.819 of ActiveState's Perl (I haven't upgraded to 5.10 yet since my IDE doesn't yet support it) under Windows XP.

Does anyone know why &SDTOUT is created?

DarkLord1 Looking for Redemption in the Monastery

In reply to "Pro Perl's" Redirecting Filehandles - Unexpected Result by DarkLord1

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.