PerlIO::code - Calls a subroutine with I/O interface
This document describes PerlIO::code version 0.03
use PerlIO::code; # need to say explicitly # make an input filter open my $in, '<', sub{ uc scalar <> }; print while <$in>; # make an output filter open my $out, '>', sub{ print uc shift }; print $out while <>; # it accepts an extra argument sub my_readline{ my($fh) = @_; my $line = <$fh>; # ...filterling... return $line; } open my $fh, '<', \&my_readline, \*STDIN;
PerlIO::code helps to make an simple I/O filter. It is easier than tie, but provides very limited functions. All it can do is to do readline() and print().
PerlIO::code
tie
readline()
print()
For some reason, the actual layer name of PerlIO::code is :Code, not :code.
:Code
:code
PerlIO::code is slower than the tie interface.
open my $in, '<', sub{ "foo" }; my $s = <$in>; makes an endless loop, because the internal readline routine reads $in on until reaching EOF, which is never reached.
open my $in, '<', sub{ "foo" }; my $s = <$in>;
readline
$in
EOF
No configuration files or environment variables.
Perl 5.8.1 or later, and a C compiler.
No bugs have been reported.
Please report any bugs or feature requests to bug-perlio-code@rt.cpan.org, or through the web interface at http://rt.cpan.org/.
bug-perlio-code@rt.cpan.org
PerlIO::Util.
Tie::Handle.
PerlIO::via.
PerlIO.
Goro Fuji <gfuji(at)cpan.org>.
Copyright (c) 2008, Goro Fuji <gfuji(at)cpan.org>. Some rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
To install PerlIO::code, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PerlIO::code
CPAN shell
perl -MCPAN -e shell install PerlIO::code
For more information on module installation, please visit the detailed CPAN module installation guide.