APM: Use of the ampersand, "&"

don james outlawtx at cox-internet.com
Fri Sep 30 06:41:47 PDT 2005


Hi,

Okay.  I have another question.  Which file handle gets duplicated?

In  the following example:

open(LOG, ">>/foo/logfile");
and later
open(STDERR, ">&LOG");

Does "LOG" become the same as "STDERR" or does "STDERR" become the same
as "LOG"?

In other words,  if the system sends messages to STDERR, does that same
message also get sent to LOG and then to /foo/logfile?

Sincerely,

Don James

Thursday, September 29, 2005Thu, 29 Sep 2005 14:05:52 -050014:05-
050014:05-0500 at 837ThomasThomas L. Shinnicktshinnic at io.com

>At 12:54 9/29/2005, Taylor Carpenter wrote:
>>don james wrote:
>>> She has an example where the "&" precedes a filename.  It is used in the
>>> following context:
>>> 
>>> open(SAVED, ">&STDOUT");
>>
>>That is for duping the file handle.  See dup(2) and perldoc -f open.
>
>perlfaq5 "How do I dup() a filehandle in Perl?" gives a good example. 
>You already have a file open, and now you want to re-use that handle when
>opening another file.
>    open(LOG, ">>/foo/logfile");
>and later
>    open(STDERR, ">&LOG");
>This allows the second open to be ignorant of what file is being used by
>the first.  Useful also if you want to force some output to wahtever
>STDERR points to
>    open(TRACE, ">&STDERR");
>without some underlying routine having to know.  Check out Test::Builder
>where they do open(TESTERR,">&STDERR') to keep a copy of STDERR in case
>the following code being tested changes where STDERR outputs to.
>
>>Taylor
>
>
>_______________________________________________
>Austin mailing list
>Austin at pm.org
>http://mail.pm.org/mailman/listinfo/austin




More information about the Austin mailing list