#!/usr/bin/perl -w # Copyright (C) 2004 Mike Irwin # This program is free software; you can redistribute it and/or modify it under # the same terms as Perl itself. # This program comes with ABSOLUTELY NO WARRANTY. # See `perldoc perlartistic'. use strict; use POSIX qw(floor); use constant SPLIT_SIZE => 3996; foreach (@ARGV) { die "$_: $!\n" unless -r; my $size = -s _; next unless $size > 4096; my $last_size = $size % SPLIT_SIZE; my $num_files = floor( $size / SPLIT_SIZE ); $num_files++ if $last_size; my ( $file, $read, $j, $data, $link ); my $width = length($num_files); open OF, "+<$_" or die "$_: $!\n"; for ( my $i = $num_files ; $i > 0 ; $i-- ) { $file = sprintf( "%s.%0*d", $_, $width, $i ); $read = 0; open NF, ">$file" or die "$file: $!\n"; seek OF, -( ( $i == $num_files and $last_size ) ? $last_size : SPLIT_SIZE ), 2; while ( $j = read OF, $data, SPLIT_SIZE ) { print NF $data; $read += $j; } print NF "...\n\nNext Page" if ( $i < $num_files ); close NF; truncate OF, $size -= $read; $link = $file; } close OF; unlink or warn "$_: $!\n"; }