Gossamer Forum
Home : General : Perl Programming :

Question

Quote Reply
Question
What does the statement 'open(SAVED, ">&STDOUT");' mean? The meaning of the '&' character has me stumpted. Apparently this syntax can be used to save the STDOUT handle ... which can be restored later by means of the following statement 'open(STDOUT, ">&SAVED"). Can't find any reference to the use of the & character in this context. What is going on here?
Quote Reply
Re: [parkerpe] Question In reply to
This is from the open POD:

Quote:
You may also, in the Bourne shell tradition, specify an EXPR beginning with '>&', in which case the rest of the string is interpreted as the name of a filehandle (or file descriptor, if numeric) to be duped and opened. You may use & after >, >>, <, +>, +>>, and +<. The mode you specify should match the mode of the original filehandle. (Duping a filehandle does not take into account any existing contents of IO buffers.) If you use the 3 arg form then you can pass either a number, the name of a filehandle or the normal "reference to a glob".

And the link: http://www.perldoc.com/...0/pod/func/open.html
(Not quite 2/3 of the way down the page)

~Charlie