NAME
IO::Util - A selection of general-utility IO function
VERSION 1.25
The latest versions changes are reported in the Changes file in this distribution.
INSTALLATION
- CPAN
-
perl -MCPAN -e 'install IO::Util'
- Standard installation
-
From the directory where this file is located, type:
perl Makefile.PL make make test make install
SYNOPSIS
use IO::Util qw(capture slurp);
# captures the selected file handler
$output_ref = capture { some_printing_code() } ;
sub some_printing_code {
print 'something'
}
# captures FILEHANDLER
$output_ref = capture { some_special_printing_code() } FILEHEANDLER ;
sub some_special_printing_code {
print FILEHANDLER 'something'
}
$_ = '/path/to/file' ;
$content_ref = slurp ;
$content_ref = slurp '/path/to/file' ;
$content_ref = slurp \*FILEHANDLER ;
DESCRIPTION
This is a micro-weight module that exports just a couple of functions of general utility in IO operations.
FUNCTIONS
capture { code } [ FILEHANDLER ]
The capture
function espects a code block as the first argument and an optional FILEHANDLER as the second argument. If FILEHANDLER is omitted the selected file handler will be used by default (usually STDOUT
). The function returns the reference to the captured output.
It executes the code inside the first argument block, and captures the output it sends to the selected file handler (or to a specific file handler). It "hijacks" all the print
and printf
statements addressed to the captured filehandler, returning the scalar reference to the output. Sort of "print to scalar" function.
Note: This function ties the FILEHANDLER to IO::Util class and unties it after the execution of the code. If FILEHANDLER is already tied to any other class, it just temporary re-bless the tied object to IO::Util class, re-blessing it again to its original class after the execution of the code, thus preserving the original FILEHANDLER configuration.
slurp [ file|FILEHANDLER ]
The slurp
function expects a path to a file or an open FILEHANDLER, and returns the reference to the whole file|FILEHANDLER content. If no argument is passed it will use $_ as the argument.
SUPPORT and FEEDBACK
If you need support or if you want just to send me some feedback or request, please use this link: http://perl.4pro.net/?IO::Util.
AUTHOR and COPYRIGHT
© 2004 by Domizio Demichelis.
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the same terms as perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 151:
Non-ASCII character seen before =encoding in '©'. Assuming CP1252