in reply to Save/restore STDIN
Other than having switched the meaning of ">" and "<", you seem to have trouble with properly using local. Zaxo gave you the right info, but was perhaps somewhat short in explaining.
The beauty of local is that you do not have to restore the variable (or filehandle in this case) after having changed it.
Everytime you use local variable, a "new" copy of this variable is made which hides the original variable for the duration of the innermost enclosing scope (this can be a block ({...}), a loop, a subroutine, ...). The "original" variable is still there, only you cannot access it. Once you leave the innermost enclosing scope, the localized value of your variable disappears and the original value is automagically restored.
So , the easiest way to solve your problem is to enclose that part of your program which needs to have STDIN redirected in a { } block as shown by Zaxo's code.
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Save/restore STDIN
by Roger (Parson) on Sep 07, 2003 at 23:00 UTC |