Perl 5 version documentation

SelectSaver

NAME

SelectSaver - save and restore selected file handle

SYNOPSIS

  1. use SelectSaver;
  2. {
  3. my $saver = SelectSaver->new(FILEHANDLE);
  4. # FILEHANDLE is selected
  5. }
  6. # previous handle is selected
  7. {
  8. my $saver = SelectSaver->new;
  9. # new handle may be selected, or not
  10. }
  11. # previous handle is selected

DESCRIPTION

A SelectSaver object contains a reference to the file handle that was selected when it was created. If its new method gets an extra parameter, then that parameter is selected; otherwise, the selected file handle remains unchanged.

When a SelectSaver is destroyed, it re-selects the file handle that was selected when it was created.