Skip to content

jberger/Tie-Select

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Provides a localized interface to the select function

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages