use SelectSaver; select $fh_old; { my $saver = new SelectSaver($fh_new); # selects $fh_new } # block ends; object pointed to by "my" $saver is destroyed # previous handle, $fh_old is now selected # alternative invocation, without filehandle argument my $saver = new SelectSaver; # selected filehandle remains unchanged
A SelectSaver object contains a reference to the filehandle that
was selected when the object was created. If its new()
method is
given a filehandle as an argument, then that filehandle is selected;
otherwise, the selected filehandle remains unchanged.
When a SelectSaver object is destroyed, the filehandle that was selected immediately prior to the object's creation is re-selected.