IO::File::Cycle - Easily split output file while writing
Version 0.03
This module makes it easy to split a file while writing to it. This, for example, will create a number of files in /tmp called "foo.1.txt", "foo.2.txt", &c., all at most 10,000 bytes in size:
use IO::File::Cycle; my $file = IO::File::Cycle->new('>/tmp/foo.txt'); for ( 1..100_000 ) { $file->cycle if tell($file) + length($_) + 1 > 10_000; print $file $_, "\n"; } $file->close;
Defines the starting number, which can be easily overridden in a subclass.
Sets up some internal variables, then calls IO::File::open().
Formats the filename.
Closes the current file, then opens a new file with an incremented number in the filename (before the extension if there is one, and after a "."). After closing the initial file, it renames it to have the index "1" – for example, "filename.1.ext".
Returns the current file's name. This can be called from a close() method in a subclass to post-process each file.
This is a sample close() method, which in a subclass could post-process each file.
sub close { my $io = shift; my $filename = $io->filename; $io->SUPER::close; system "gzip -f $filename"; }
Nic Wolff, <nic at angel.net>
<nic at angel.net>
Please report any bugs or feature requests to bug-io-file-cycle at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=IO-File-Cycle. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-io-file-cycle at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc IO::File::Cycle
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=IO-File-Cycle
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/IO-File-Cycle
CPAN Ratings
http://cpanratings.perl.org/d/IO-File-Cycle
Search CPAN
http://search.cpan.org/dist/IO-File-Cycle/
Copyright 2012 Nic Wolff.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in '– for'. Assuming UTF-8
To install IO::File::Cycle, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::File::Cycle
CPAN shell
perl -MCPAN -e shell install IO::File::Cycle
For more information on module installation, please visit the detailed CPAN module installation guide.