Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Provides a localized interface to the select function

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 t
Octocat-spinner-32 xt
Octocat-spinner-32 Build.PL
Octocat-spinner-32 README.pod
README.pod

NAME

Tie::Select - Provides a localized interface to the select function

SYNOPSIS

 use strict; use warnings;
 use Tie::Select;

 {
   local $SELECT = *STDERR;
   print "This goes to STDERR";
 }

 print "This goes to STDOUT";

DESCRIPTION

The Perl builtin print, when not called with an explicit file handle, will print to the file handle designated by the select command. This is a global action, which is bad. Further, it has an awkward interface for restoring a previous handle; on a call to select a reference to the old handle is returned, which has to itself be select-ed to restore the old handle. Better to see an example.

 my $stdout = select *STDERR;
 print "To STDERR";
 select $stdout;
 print "To STDOUT";

Tie::Select offers a localizable interface to select. Simply assign a handle to the $SELECT variable provided by this module to change the select-ed handle. If this is done with local the change is dynamically bound to the enclosing scope. Therefore the above example becomes simply:

 {
   local $SELECT = *STDERR;
   print "To STDERR";
 }

The inspiration for this type of interface is File::chdir which provides a similar localizable interface to the current working directory.

SEE ALSO

  • File::chdir - Allow localized working directory, inspiration for this module
  • Lexical::select - As the name implies, it provides a lexically scoped interface to the select function rather than dynamically scoped
  • IO::Select - This time its an Object-Oriented interface to select

SOURCE REPOSITORY

http://github.com/jberger/Tie-Select

AUTHOR

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Something went wrong with that request. Please try again.